can-symbol
Version:
Well known symbols used to detail how to operate on different objects
34 lines (26 loc) • 1.08 kB
Markdown
function(String, function(*))} can-symbol/symbols/offKeyValue can.offKeyValue
can-symbol/symbols/observe
Defines how observable values can be listened to on a type.
`@@can.offKeyValue( key, handler(newValue) )`
the `@@@@can.offKeyValue` symbol is placed on a Map-like object to point to a function used to stop listening to changes on the `key` property with the `handler` function.
```
var obj = {
handlers: {},
setKeyValue: function(key, value){
this[key] = value;
var self = this;
obj.handlers[key].forEach(function(handler){
handler.call(self, value);
});
}
};
obj[canSymbol.for("can.offKeyValue")] = function(key, handler){
if(!obj.handlers[key]) {
obj.handlers[key] = [];
}
obj.handlers[key].splice(obj.handlers[key].indexOf(handler), 1);
}
```
{Object} any Map-like object with named properties
{String} key the string key to stop binding on changes to.
{function(this:*, *)} handler(newValue) The handler that was previously bound with [can-symbol/symbols/onKeyValue `@@can.onKeyValue`]
{