Add a watcher data source, to watch expression changes, and trigger events.
With this data source, developer don't have to add onChange event for every component's state. It is also very useful to complicated expression.
The usage is like:
Note that the exp property requires a string in expression format without {{}}. This is to prevent the exp being evaled when compiling template.
I'm not sure if we need to provide a Watcher at runtime. Because when listening for state changes to do something, it is easier to use it incorrectly.
Why not just pass in the expression and listen for changes in its value directly in Watcher, instead of compiling it in Watcher? Writing plain strings has no editor prompt and is error-prone
@MrWindlike I changed implementation. Now the component implementation get raw exp from component.properties, so that user can have editor prompt when entering exp.
Add a
watcher
data source, to watch expression changes, and trigger events. With this data source, developer don't have to addonChange
event for every component's state. It is also very useful to complicated expression.The usage is like:
Note that the
exp
property requires a string in expression format without{{}}
. This is to prevent theexp
being evaled when compiling template.