Skip to content

Specifying the deep/immediate flags on watches is awkward #31

@thecodewarrior

Description

@thecodewarrior

Background

Currently, defining a watcher with either the deep or immediate flags requires a watch property with an object value that specifies the handler and flags. This is awkward and breaks type checking because this isn't defined.

@VueStore
class Store {
  prop = {value: 10}

  'on:prop' = {
    handler: function() {
      this.prop // type error because `this` isn't defined
    },
    deep: true
  }
}

That's in the Vue 2 branch. Due to the way the watches are created in the Vue 3 branch, setting those flags is impossible so your only option is to manually call watch yourself.

Proposal

I propose a suffix syntax for setting these flags. The flags would be defined, comma-separated, after a pound sign. e.g. 'on:prop#deep' or 'on:prop#deep,immediate'.

In Vue 2 the only flags will be deep and immediate. Vue 3 adds the flush watch option, which adds three more (mutually exclusive) flags: pre, post, and sync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions