onKeyValue
Register an event handler on a MapLike object, based on a key change
onKeyValue(obj, key, handler, [queueName])
Register a handler on the Map-like object obj to trigger when the property key key changes.
obj must implement @@can.onKeyValue to be compatible with
can-reflect.onKeyValue. The function passed as handler will receive the new value of the property
as the first argument, and the previous value of the property as the second argument.
var obj = new DefineMap({ foo: "bar" });
canReflect.onKeyValue(obj, "foo", function(newVal, oldVal) {
console.log("foo is now", newVal, ", was", oldVal);
});
obj.foo = "baz"; // -> logs "foo is now baz , was bar"
Parameters
- obj
{Object}:an observable MapLike that can listen to changes in named properties.
- key
{String}:the key to listen to
- handler
{function(*, *)}:a callback function that recieves the new value
- queueName
{String}:the queue to dispatch events to