diff --git a/docs/apis.json b/docs/apis.json deleted file mode 100644 index f555286..0000000 --- a/docs/apis.json +++ /dev/null @@ -1,47 +0,0 @@ -[ - {"can-symbol": [ - "can-symbol.for", - "can-symbol.keyFor", - {"can-symbol/symbols/type": [ - "can-symbol/symbols/isMapLike", - "can-symbol/symbols/isListLike", - "can-symbol/symbols/isValueLike" - ]}, - {"can-symbol/symbols/shape": [ - "can-symbol/symbols/getOwnKeys", - "can-symbol/symbols/getOwnKeyDescriptor", - "can-symbol/symbols/proto", - "can-symbol/symbols/getOwnEnumerableKeys", - "can-symbol/symbols/hasOwnKey" - ]}, - {"can-symbol/symbols/get-set": [ - "can-symbol/symbols/getValue", - "can-symbol/symbols/setValue", - "can-symbol/symbols/getKeyValue", - "can-symbol/symbols/setKeyValue", - "can-symbol/symbols/deleteKeyValue" - ]}, - {"can-symbol/symbols/call": [ - "can-symbol/symbols/apply", - "can-symbol/symbols/new" - ]}, - {"can-symbol/symbols/observe": [ - "can-symbol/symbols/onValue", - "can-symbol/symbols/offValue", - "can-symbol/symbols/onKeyValue", - "can-symbol/symbols/offKeyValue", - "can-symbol/symbols/getKeyDependencies", - "can-symbol/symbols/getValueDependencies", - "can-symbol/symbols/keyHasDependencies", - "can-symbol/symbols/valueHasDependencies", - "can-symbol/symbols/onKeys", - "can-symbol/symbols/onKeysAdded", - "can-symbol/symbols/onKeysRemoved" - ]} - ]} -] - - - - - diff --git a/docs/symbols-offEmit.md b/docs/symbols-offEmit.md new file mode 100644 index 0000000..f2180a9 --- /dev/null +++ b/docs/symbols-offEmit.md @@ -0,0 +1,32 @@ +@typedef {function(function(*))} can-symbol/symbols/offEmit can.offEmit +@parent can-symbol/symbols/observe +@description Defines how observables can stop listening to the object's value being emitted. + +@signature `@@can.offEmit( handler(newValue) )` + +The `@@@@can.offEmit` symbol points to a function that unregisters + `handler` from being called when the object's value + is emitted. + +```js +const obj = function(value) { + if(arguments.length >= 1) { + obj.currentValue = value; + obj.handlers.forEach(function(handler){ + handler.call(obj, value); + }); + } else { + return obj.currentValue; + } +}; + +obj[canSymbol.for("can.offEmit")] = function(handler){ + if(!obj.handlers) { + obj.handlers = []; + } + obj.handlers.splice(obj.handlers.indexOf(handler), 1); +} +``` + +@this {*} any object with a mutable value +@param {function(this:*, *)} handler(newValue) The handler was previously added with [can-symbol/symbols/onEmit `@@can.onEmit`]. diff --git a/docs/symbols-onEmit.md b/docs/symbols-onEmit.md new file mode 100644 index 0000000..d3de4da --- /dev/null +++ b/docs/symbols-onEmit.md @@ -0,0 +1,41 @@ +@typedef {function(function(*))} can-symbol/symbols/onEmit can.onEmit +@parent can-symbol/symbols/observe +@description Defines how observables can listen to the object's value whenever it is emitted. + +@signature `@@can.onEmit( handler(newValue) )` + +The `@@@@can.onEmit` symbol points to a function that registers + `handler` to be called back with the new value of the object when it + is emitted. `@@@@can.onEmit` can be used when you wish to emit a value that isn't changing. + +```js +const obj = function(value) { + if(arguments.length >= 1) { + obj.currentValue = value; + obj.handlers.forEach(function(handler){ + handler.call(obj, value); + }); + } else { + return obj.currentValue; + } +}; + +obj[canSymbol.for("can.onEmit")] = function(handler){ + if(!obj.handlers) { + obj.handlers = []; + } + obj.handlers.push(handler); +} + +const listener = function (value) { + console.log('emitted', value); +} + +obj[canSymbol.for("can.onEmit")](listener); + +obj(5); // -> output: "emitted 5" +obj(5); // -> output: "emitted 5" +``` + +@this {*} any object with a mutable value +@param {function(this:*, *)} handler(newValue) The handler must be called back with `this` as the instance of the observable.