onValue
Register an event handler on an observable ValueLike object, based on a change in its value
onValue(handler, [queueName])
Register an event handler on the Value-like object obj
to trigger when its value changes.
obj
must implement @@can.onValue to be compatible with
can-reflect.onKeyValue. The function passed as handler
will receive the new value of obj
as the first argument, and the previous value of obj
as the second argument.
var obj = canCompute("foo");
canReflect.onValue(obj, function(newVal, oldVal) {
console.log("compute is now", newVal, ", was", oldVal);
});
obj("bar"); // -> logs "compute is now bar , was foo"
Parameters
- obj
{*}
:any object implementing @@can.onValue
- handler
{function(*, *)}
:a callback function that receives the new and old values