observable
observable
observable(value) @observable classProperty = value
// If the value is an instance of the ES6 Map: returns a new Observable Map. Not only concerned about changes to a particular entry, but also to change when adding or deleting other entry also respond. // If the value is an array, returns an Observable Array. // If the value is not a prototype or a prototype object is Object.prototype, then the object is cloned and all of the attributes will be converted into observable. // If there is a value of the object prototype, the JavaSript primitive data types or functions, does not change the value. If you need Boxed Observable: 1 , explicitly call observable.box (value)
// observable.box (? Value, Options), // Use get () method can get the current value of the box, and use the set () method to update the value // Use {deep: false} option disables the new value observable.
2 , when using the class definition @observable, // is extendObservable(this, { property: value })
syntactic sugar
3 , calling the decorate ()
. 4 , extendObservable used in class () introduced properties
// To use @observable decorator, we must first ensure that the compiler (babel or typescript) in the decorator is enabled. // default to a translation data structure is observed to be infectious, which means are automatically applied to any observable data structure contains a value, or the value of the data structure is contained in the future. This behavior can be changed by using the decorator
// create an object provides a clone and all its properties converted into observable // Use {deep: false} only property will be converted into observable quoted option, the value will not change (this also applies to any future distribution of value). Observable. Object (value, Decorators ?, Options? ) observable.array (value, Options ? ) // create a new array based on observable value provided. observable.map (value, Options ? ) // create a new value based on observable provide mapping to create a dynamic set of keys need to be able to observe and to add and remove keys, keys can be used freely without any strings limited .
extendObservable (target, the Properties, Options Decorators ?,? ) // extendObservable enhance existing objects, unlike observable.object is to create a new object // If a new attribute should not have infectious, extendObservable (target, The props, Decorators ?, {Deep: to false} )
Decorator (Decorators)
observable.deep: // default decorators are using all observable. It can convert any specified non-primitive data type, into a non-observable observable value. observable. ref : // disable the automatic conversion of observable, observable only create a reference. observable.shallow: // can only be used in combination with the collection. Converting any set of allocated as a pale Observable (but not dark Observable) collection. In other words, the set value will not automatically become observable. computed: // create a derivative properties action: // Create an action