Avalon's ViewModel object inherits three methods from its internal eventmanager , $watch, $unwatch, $fire three methods that are the subject of our section.
Words, like their name, are very straightforward and know what to do at a glance. Let's start with the $watch method, which listens to the monitoring and calculation Properties of the first layer of the current VM, and if an attribute is an object that wants to monitor its descendants ' properties, it needs to navigate to the object using the $watch callback. The $watch callback defaults to the two attribute values that are passed in.
<! DOCTYPE html><! DOCTYPE html><! DOCTYPE html>Note that the $watch callback is the new API object.is provided by ecma262 V6 , which has the same function as = = = , but can deal with NaN This himself is not equal to his own freak. Also, an object literal, even if it looks the same, is a new object and will not be equal to the original.
<! DOCTYPE html>For arrays, we can only listen for changes in the length of the array, and cannot listen for changes in its interior.
<! DOCTYPE html><! DOCTYPE html>
- Up!xxx, bubble up.
- Down!xxx, capturing down
- ALL!XXX, Global Broadcast
<! DOCTYPE html>Mini MVVM Framework Avalonjs Learning Tutorial 15, attribute monitoring and module communication