onPatches
Register an handler on an observable that listens to any key changes
onPatches(obj, handler, [queueName])
Register an event handler on the object obj
that fires when anything changes on an object: a key value is added,
an existing key has is value changed, or a key is deleted from the object.
If object is an array-like and the changed property includes numeric indexes, patch sets will include array-specific patches in addition to object-style patches
For more on the patch formats, see diff-object and diff-array.
var obj = new DefineMap({});
var handler = function(patches) {
console.log(patches);
};
canReflect.onPatches(obj, handler);
obj.set("foo", "bar"); // logs [{ type: "add", property: "foo", value: "bar" }]
obj.set("foo", "baz"); // logs [{ type: "set", property: "foo", value: "baz" }]
var arr = new DefineList([]);
canReflect.onPatches(arr, handler);
arr.push("foo"); // logs [{type: "add", property:"0", value: "foo"},
{index: 0, deleteCount: 0, insert: ["foo"]}]
arr.pop(); // logs [{type: "remove", property:"0"},
{index: 0, deleteCount: 1, insert: []}]
Parameters
- obj
{*}
: - handler
{function(*)}
: - queueName
{String}
:the name of a queue in [can-queues]; dispatches to
handler
will happen on this queue