Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add @WatchSub decorator #28

Closed
wants to merge 2 commits into from

Conversation

vanhoavn
Copy link

@vanhoavn vanhoavn commented Dec 11, 2016

Add @WatchSub decorator to handle key-path watches @WatchSub('variable.key1.key2').
(Add this ass new decorator so normal check for single property watch @Watch can still be useful).

@HerringtonDarkholme
Copy link
Owner

HerringtonDarkholme commented Dec 11, 2016

Hi @vanhoavn , thanks for your contribution.

Actually I have considered key-path watch when designing this library. I deliberately leave it in component meta data since I cannot type check keypath.

If you need watch key path, you can do it in Component

@Component({
  watch: {
    'variable.key1.key2': handler,
  }
})
class Comp extends Vue {}

Also, key-path type checking is possible in new TypeScript. microsoft/TypeScript#12290 (comment). I wonder whether it is good enough for average users so I didn't include it. Maybe it is a better alternative than WatchSub.

Thanks for your contribution again

@vanhoavn
Copy link
Author

Thanks, that's why i made it as a new decorator, putting functions in the meta require casting this to Comp before all use, while with decorator we can better organize the code into folding blocks.

@vanhoavn
Copy link
Author

The new TypeScript's key-path type checking you mentioned above use array to hold each element in path's type so they can statically checked, while in Vue we use dotted notation, which require split before any subsequence checking.

@HerringtonDarkholme
Copy link
Owner

I will implement key path watch in new version. Please wait.

@HerringtonDarkholme
Copy link
Owner

Supported in 0.6.1

Warn beforehand: nested watch is not a good practice, in fact, watch is a helper shortcut which can be substituted by computed properties.

Adding watch path in component meta is a warning embodied by API design, actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants