can-symbol
Version:
Well known symbols used to detail how to operate on different objects
33 lines (27 loc) • 901 B
Markdown
*))} can-symbol/symbols/onValue can.onValue
can-symbol/symbols/observe
Defines how observables can listen to the object's value changing.
`@ .onValue( handler(newValue) )`
The `@@@ .onValue` symbol points to a function that registers
`handler` to be called back with the new value of the object when it
changes.
```
var obj = function(value) {
if(arguments.length >= 1) {
obj.currentValue = value;
obj.handlers.forEach(function(handler){
handler.call(obj, value);
});
} else {
return obj.currentValue;
}
};
obj[canSymbol.for("can.onValue")] = function(handler){
if(!obj.handlers) {
obj.handlers = [];
}
obj.handlers.push(handler);
}
```
{*} any object with a mutable value
{function(this:*, *)} handler(newValue) The handler must be called back with `this` as the instance of the observable.
{function(function(