Comparing version 5.0.0 to 6.0.0
{ | ||
"name": "diode", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "A simple event emitter.", | ||
"main": "src/diode.js", | ||
"scripts": { | ||
"test": "mocha -R dot", | ||
"test:watch": "mocha -R dot -w" | ||
}, | ||
"repository": { | ||
@@ -20,3 +24,6 @@ "type": "git", | ||
"bugs": "https://github.com/vigetlabs/diode/issues", | ||
"homepage": "https://github.com/vigetlabs/diode" | ||
"homepage": "https://github.com/vigetlabs/diode", | ||
"devDependencies": { | ||
"mocha": "2.3.2" | ||
} | ||
} |
/** | ||
* The Diode emits a heartbeat whenever any store state has changed. | ||
* When Stores change, they can use this entity to broadcast | ||
* that state has changed. | ||
* Event subscription for Microcosm | ||
*/ | ||
'use strict'; | ||
var Diode = function (app) { | ||
var callbacks = [] | ||
function Diode(target) { | ||
var _callbacks = []; | ||
if (this instanceof Diode) { | ||
target = this; | ||
} else { | ||
target = target || {}; | ||
app = this | ||
} else if (arguments.length == 0){ | ||
return new Diode() | ||
} | ||
@@ -21,23 +17,18 @@ | ||
*/ | ||
target.listen = target.subscribe = function (callback) { | ||
if (typeof callback !== 'function') { | ||
throw new TypeError('callback must be a function'); | ||
} | ||
app.listen = app.subscribe = function (callback) { | ||
callbacks.push(callback) | ||
return app | ||
} | ||
_callbacks.push(callback); | ||
return target; | ||
}; | ||
/** | ||
* Given a CALLBACK function, remove it from the set of callbacks. | ||
* Throws an error if the callback is not included in the Set. | ||
* Throws an error if the callback is not included in the set. | ||
*/ | ||
target.ignore = target.unsubscribe = function (callback) { | ||
_callbacks = _callbacks.filter(function (i) { | ||
return i !== callback; | ||
}); | ||
app.ignore = app.unsubscribe = function (unwanted) { | ||
callbacks = callbacks.filter(function(entry) { | ||
return entry !== unwanted | ||
}) | ||
return target; | ||
}; | ||
return app | ||
} | ||
@@ -47,24 +38,13 @@ /** | ||
*/ | ||
target.emit = target.publish = function () { | ||
/** | ||
* Important: do not cache the length of _callbacks | ||
* in the event a callback causes later subscriptions | ||
* to disappear | ||
*/ | ||
for (var i = 0; i < _callbacks.length; i++) { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_callbacks[i].apply(target, args); | ||
app.emit = app.publish = function () { | ||
for (var i = 0; i < callbacks.length; i++) { | ||
callbacks[i].apply(app, arguments) | ||
} | ||
return target; | ||
}; | ||
return app | ||
} | ||
return target; | ||
return app | ||
} | ||
module.exports = Diode(Diode); | ||
module.exports.decorate = Diode; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kaW9kZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7OztBQU1BLFNBQVMsS0FBSyxDQUFFLE1BQU0sRUFBRTtBQUN0QixNQUFJLFVBQVUsR0FBRyxFQUFFLENBQUE7O0FBRW5CLE1BQUksSUFBSSxZQUFZLEtBQUssRUFBRTtBQUN6QixVQUFNLEdBQUcsSUFBSSxDQUFBO0dBQ2QsTUFBTTtBQUNMLFVBQU0sR0FBRyxNQUFNLElBQUksRUFBRSxDQUFBO0dBQ3RCOzs7OztBQUtELFFBQU0sQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDLFNBQVMsR0FBRyxVQUFVLFFBQVEsRUFBRTtBQUNyRCxRQUFJLE9BQU8sUUFBUSxLQUFLLFVBQVUsRUFBRTtBQUNsQyxZQUFNLElBQUksU0FBUyxDQUFDLDZCQUE2QixDQUFDLENBQUE7S0FDbkQ7O0FBRUQsY0FBVSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQTs7QUFFekIsV0FBTyxNQUFNLENBQUE7R0FDZCxDQUFBOzs7Ozs7QUFNRCxRQUFNLENBQUMsTUFBTSxHQUFHLE1BQU0sQ0FBQyxXQUFXLEdBQUcsVUFBVSxRQUFRLEVBQUU7QUFDdkQsY0FBVSxHQUFHLFVB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xpc2ggPSBmdW5jdGlvbiAoLi4uYXJncykge1xuICAgIC8qKlxuICAgICAqIEltcG9ydGFudDogZG8gbm90IGNhY2hlIHRoZSBsZW5ndGggb2YgX2NhbGxiYWNrc1xuICAgICAqIGluIHRoZSBldmVudCBhIGNhbGxiYWNrIGNhdXNlcyBsYXRlciBzdWJzY3JpcHRpb25zXG4gICAgICogdG8gZGlzYXBwZWFyXG4gICAgICovXG4gICAgZm9yICh2YXIgaSA9IDA7IGkgPCBfY2FsbGJhY2tzLmxlbmd0aDsgaSsrKSB7XG4gICAgICBfY2FsbGJhY2tzW2ldLmFwcGx5KHRhcmdldCwgYXJncylcbiAgICB9XG5cbiAgICByZXR1cm4gdGFyZ2V0XG4gIH1cblxuICByZXR1cm4gdGFyZ2V0XG59XG5cbm1vZHVsZS5leHBvcnRzID0gRGlvZGUoRGlvZGUpXG5tb2R1bGUuZXhwb3J0cy5kZWNvcmF0ZSA9IERpb2RlXG4iXX0= | ||
module.exports = Diode(Diode) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10
0
7882
1
39