onInstanceBoundChange
Listen to when observables of a type are bound and unbound.
onInstanceBoundChange(Type, handler, [queueName])
Register an event handler on the object Type
that fires when instances of the type become bound (the first handler is added)
or unbound (the last remaining handler is removed). The function passed as handler
will be called
with the instance
as the first argument and true
as the second argument when instance
gains its first binding,
and called with false
when instance
loses its
last binding.
Person = DefineMap.extend({ ... });
var person = Person({});
var handler = function(instance, newVal) {
console.log(instance, "bound state is now", newVal);
};
var keyHandler = function() {};
canReflect.onInstanceBoundChange(Person, handler);
canReflect.onKeyValue(obj, "name", keyHandler); // logs person Bound state is now true
canReflect.offKeyValue(obj, "name", keyHandler); // logs person Bound state is now false
Parameters
- Type
{function}
:A constructor function
- handler
{function(instance, isBound)}
:A function called with the
instance
whose bound status changed and the state of the bound status. - queueName
{String}
:the name of a queue in [can-queues]; dispatches to
handler
will happen on this queue