adverb-signals
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -1,2 +0,2 @@ | ||
# Change Log for Adverb-Signals | ||
# Change Log for [Adverb-Signals](https://github.com/sholladay/adverb-signals) | ||
All notable changes to this project are documented here, under these categories. | ||
@@ -20,2 +20,12 @@ - **Added** : New functionality or something very noteworthy. | ||
## [1.0.0] - 2015-08-25 | ||
### Changed | ||
- APIs are now named as intended for this project. | ||
-- `dispatch()` becomes `emit()` | ||
-- `add()` becomes `always()` | ||
-- `addOnce()` becomes `once()` | ||
-- `remove()` becomes `never()` | ||
-- `removeAll()` becomes `neverAny()` | ||
- For consistency with other methods, `runs()` (formerly known as `has()`) now asserts that its `listener` argument is a function, throwing if that is not the case. | ||
## 0.1.0 - 2015-08-24 | ||
@@ -26,2 +36,3 @@ ### Added | ||
[Unreleased]: https://github.com/sholladay/adverb-signals/compare/v0.1.0...HEAD | ||
[Unreleased]: https://github.com/sholladay/adverb-signals/compare/v1.0.0...HEAD | ||
[1.0.0]: https://github.com/sholladay/adverb-signals/compare/v0.1.0...v1.0.0 |
@@ -8,3 +8,3 @@ /*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */ | ||
* Author: Miller Medeiros | ||
* Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) | ||
* Version: 1.0.0 - Build: 275 (2015/08/25 07:08 PM) | ||
*/ | ||
@@ -79,3 +79,3 @@ | ||
/** | ||
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters) | ||
* Default parameters passed to listener during `Signal.emit` and `SignalBinding.execute`. (curried parameters) | ||
* @type Array|null | ||
@@ -87,3 +87,3 @@ */ | ||
* Call listener passing arbitrary parameters. | ||
* <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p> | ||
* <p>If binding was added using `Signal.once()` it will be automatically removed from signal emit queue, this method is used internally for the signal emit.</p> | ||
* @param {Array} [paramsArr] Array of parameters that should be passed to the listener | ||
@@ -106,7 +106,7 @@ * @return {*} Value returned by the listener. | ||
* Detach binding from signal. | ||
* - alias to: mySignal.remove(myBinding.getListener()); | ||
* - alias to: mySignal.never(myBinding.getListener()); | ||
* @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. | ||
*/ | ||
detach : function () { | ||
return this.isBound()? this._signal.remove(this._listener, this.context) : null; | ||
return this.isBound()? this._signal.never(this._listener, this.context) : null; | ||
}, | ||
@@ -157,4 +157,6 @@ | ||
return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']'; | ||
} | ||
}, | ||
constructor : SignalBinding | ||
}; | ||
@@ -168,5 +170,5 @@ | ||
function validateListener(listener, fnName) { | ||
function validateListener(listener, api) { | ||
if (typeof listener !== 'function') { | ||
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) ); | ||
throw new Error( 'listener is a required param of ' + (api.displayName || api.name) + '() and should be a Function.' ); | ||
} | ||
@@ -190,6 +192,6 @@ } | ||
// enforce dispatch to aways work on same context (#47) | ||
// enforce emit to aways work on same context (#47) | ||
var self = this; | ||
this.dispatch = function(){ | ||
Signal.prototype.dispatch.apply(self, arguments); | ||
this.emit = function emit() { | ||
Signal.prototype.emit.apply(self, arguments); | ||
}; | ||
@@ -208,5 +210,5 @@ } | ||
/** | ||
* If Signal should keep record of previously dispatched parameters and | ||
* automatically execute listener during `add()`/`addOnce()` if Signal was | ||
* already dispatched before. | ||
* If Signal should keep record of previously emitted parameters and | ||
* automatically execute listener during `always()`/`once()` if Signal was | ||
* already emitted before. | ||
* @type boolean | ||
@@ -224,3 +226,3 @@ */ | ||
* If Signal is active and should broadcast events. | ||
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p> | ||
* <p><strong>IMPORTANT:</strong> Setting this property during an emit will only affect the next emit, if you want to stop the propagation of a signal use `halt()` instead.</p> | ||
* @type boolean | ||
@@ -238,3 +240,3 @@ */ | ||
*/ | ||
_registerListener : function (listener, isOnce, listenerContext, priority) { | ||
_registerListener : function _registerListener(listener, isOnce, listenerContext, priority) { | ||
@@ -247,3 +249,3 @@ var prevIndex = this._indexOfListener(listener, listenerContext), | ||
if (binding.isOnce() !== isOnce) { | ||
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); | ||
throw new Error('You cannot '+ (isOnce? 'always' : 'once') +'() then '+ (!isOnce? 'always' : 'once') +'() the same listener without removing the relationship first.'); | ||
} | ||
@@ -266,3 +268,3 @@ } else { | ||
*/ | ||
_addBinding : function (binding) { | ||
_addBinding : function _addBinding(binding) { | ||
//simplified insertion sort | ||
@@ -279,3 +281,3 @@ var n = this._bindings.length; | ||
*/ | ||
_indexOfListener : function (listener, context) { | ||
_indexOfListener : function _indexOfListener(listener, context) { | ||
var n = this._bindings.length, | ||
@@ -298,3 +300,4 @@ cur; | ||
*/ | ||
has : function (listener, context) { | ||
runs : function runs(listener, context) { | ||
validateListener(listener, runs); | ||
return this._indexOfListener(listener, context) !== -1; | ||
@@ -310,4 +313,4 @@ }, | ||
*/ | ||
add : function (listener, listenerContext, priority) { | ||
validateListener(listener, 'add'); | ||
always : function always(listener, listenerContext, priority) { | ||
validateListener(listener, always); | ||
return this._registerListener(listener, false, listenerContext, priority); | ||
@@ -323,4 +326,4 @@ }, | ||
*/ | ||
addOnce : function (listener, listenerContext, priority) { | ||
validateListener(listener, 'addOnce'); | ||
once : function once(listener, listenerContext, priority) { | ||
validateListener(listener, once); | ||
return this._registerListener(listener, true, listenerContext, priority); | ||
@@ -330,3 +333,3 @@ }, | ||
/** | ||
* Remove a single listener from the dispatch queue. | ||
* Remove a single listener from the emit queue. | ||
* @param {Function} listener Handler function that should be removed. | ||
@@ -336,4 +339,4 @@ * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). | ||
*/ | ||
remove : function (listener, context) { | ||
validateListener(listener, 'remove'); | ||
never : function never(listener, context) { | ||
validateListener(listener, never); | ||
@@ -351,3 +354,3 @@ var i = this._indexOfListener(listener, context); | ||
*/ | ||
removeAll : function () { | ||
neverAny : function neverAny() { | ||
var n = this._bindings.length; | ||
@@ -363,3 +366,3 @@ while (n--) { | ||
*/ | ||
getNumListeners : function () { | ||
getNumListeners : function getNumListeners() { | ||
return this._bindings.length; | ||
@@ -369,7 +372,7 @@ }, | ||
/** | ||
* Stop propagation of the event, blocking the dispatch to next listeners on the queue. | ||
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p> | ||
* Stop propagation of the event, blocking the emit to next listeners on the queue. | ||
* <p><strong>IMPORTANT:</strong> should be called only during signal emit, calling it before/after emit won't affect signal broadcast.</p> | ||
* @see Signal.prototype.disable | ||
*/ | ||
halt : function () { | ||
halt : function halt() { | ||
this._shouldPropagate = false; | ||
@@ -379,6 +382,6 @@ }, | ||
/** | ||
* Dispatch/Broadcast Signal to all listeners added to the queue. | ||
* Emit/Broadcast Signal to all listeners added to the queue. | ||
* @param {...*} [params] Parameters that should be passed to each handler. | ||
*/ | ||
dispatch : function (params) { | ||
emit : function emit(params) { | ||
if (! this.active) { | ||
@@ -401,4 +404,4 @@ return; | ||
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch | ||
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. | ||
bindings = this._bindings.slice(); //clone array in case add/remove items during emit | ||
this._shouldPropagate = true; //in case `halt` was called before emit or during the previous emit. | ||
@@ -414,3 +417,3 @@ //execute all callbacks until end of the list or until a callback returns `false` or stops propagation | ||
*/ | ||
forget : function(){ | ||
forget : function forget() { | ||
this._prevParams = null; | ||
@@ -423,4 +426,4 @@ }, | ||
*/ | ||
dispose : function () { | ||
this.removeAll(); | ||
dispose : function dispose() { | ||
this.neverAny(); | ||
delete this._bindings; | ||
@@ -433,6 +436,8 @@ delete this._prevParams; | ||
*/ | ||
toString : function () { | ||
toString : function toString() { | ||
return '[Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']'; | ||
} | ||
}, | ||
constructor : Signal | ||
}; | ||
@@ -439,0 +444,0 @@ |
@@ -6,10 +6,10 @@ /* | ||
Author: Miller Medeiros | ||
Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) | ||
Version: 1.0.0 - Build: 275 (2015/08/25 07:08 PM) | ||
*/ | ||
(function(i){function h(a,b,c,d,e){this._listener=b;this._isOnce=c;this.context=d;this._signal=a;this._priority=e||0}function g(a,b){if(typeof a!=="function")throw Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",b));}function e(){this._bindings=[];this._prevParams=null;var a=this;this.dispatch=function(){e.prototype.dispatch.apply(a,arguments)}}h.prototype={active:!0,params:null,execute:function(a){var b;this.active&&this._listener&&(a=this.params?this.params.concat(a): | ||
a,b=this._listener.apply(this.context,a),this._isOnce&&this.detach());return b},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal;delete this._listener;delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+ | ||
", isBound:"+this.isBound()+", active:"+this.active+"]"}};e.prototype={VERSION:"1.0.0",memorize:!1,_shouldPropagate:!0,active:!0,_registerListener:function(a,b,c,d){var e=this._indexOfListener(a,c);if(e!==-1){if(a=this._bindings[e],a.isOnce()!==b)throw Error("You cannot add"+(b?"":"Once")+"() then add"+(!b?"":"Once")+"() the same listener without removing the relationship first.");}else a=new h(this,a,b,c,d),this._addBinding(a);this.memorize&&this._prevParams&&a.execute(this._prevParams);return a}, | ||
_addBinding:function(a){var b=this._bindings.length;do--b;while(this._bindings[b]&&a._priority<=this._bindings[b]._priority);this._bindings.splice(b+1,0,a)},_indexOfListener:function(a,b){for(var c=this._bindings.length,d;c--;)if(d=this._bindings[c],d._listener===a&&d.context===b)return c;return-1},has:function(a,b){return this._indexOfListener(a,b)!==-1},add:function(a,b,c){g(a,"add");return this._registerListener(a,!1,b,c)},addOnce:function(a,b,c){g(a,"addOnce");return this._registerListener(a, | ||
!0,b,c)},remove:function(a,b){g(a,"remove");var c=this._indexOfListener(a,b);c!==-1&&(this._bindings[c]._destroy(),this._bindings.splice(c,1));return a},removeAll:function(){for(var a=this._bindings.length;a--;)this._bindings[a]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(a){if(this.active){var b=Array.prototype.slice.call(arguments),c=this._bindings.length,d;if(this.memorize)this._prevParams= | ||
b;if(c){d=this._bindings.slice();this._shouldPropagate=!0;do c--;while(d[c]&&this._shouldPropagate&&d[c].execute(b)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll();delete this._bindings;delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}};var f=e;f.Signal=e;typeof define==="function"&&define.amd?define(function(){return f}):typeof module!=="undefined"&&module.exports?module.exports=f:i.signals= | ||
f})(this); | ||
(function(m){function l(a,b,e,d,c){this._listener=b;this._isOnce=e;this.context=d;this._signal=a;this._priority=c||0}function j(a,b){if(typeof a!=="function")throw Error("listener is a required param of "+(b.displayName||b.name)+"() and should be a Function.");}function i(){this._bindings=[];this._prevParams=null;var a=this;this.emit=function(){i.prototype.emit.apply(a,arguments)}}l.prototype={active:!0,params:null,execute:function(a){var b;this.active&&this._listener&&(a=this.params?this.params.concat(a): | ||
a,b=this._listener.apply(this.context,a),this._isOnce&&this.detach());return b},detach:function(){return this.isBound()?this._signal.never(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal;delete this._listener;delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+ | ||
", isBound:"+this.isBound()+", active:"+this.active+"]"},constructor:l};i.prototype={VERSION:"1.0.0",memorize:!1,_shouldPropagate:!0,active:!0,_registerListener:function(a,b,e,d){var c=this._indexOfListener(a,e);if(c!==-1){if(a=this._bindings[c],a.isOnce()!==b)throw Error("You cannot "+(b?"always":"once")+"() then "+(!b?"always":"once")+"() the same listener without removing the relationship first.");}else a=new l(this,a,b,e,d),this._addBinding(a);this.memorize&&this._prevParams&&a.execute(this._prevParams); | ||
return a},_addBinding:function(a){var b=this._bindings.length;do--b;while(this._bindings[b]&&a._priority<=this._bindings[b]._priority);this._bindings.splice(b+1,0,a)},_indexOfListener:function(a,b){for(var e=this._bindings.length,d;e--;)if(d=this._bindings[e],d._listener===a&&d.context===b)return e;return-1},runs:function b(e,d){j(e,b);return this._indexOfListener(e,d)!==-1},always:function e(d,c,f){j(d,e);return this._registerListener(d,!1,c,f)},once:function d(c,f,g){j(c,d);return this._registerListener(c, | ||
!0,f,g)},never:function c(f,g){j(f,c);var h=this._indexOfListener(f,g);h!==-1&&(this._bindings[h]._destroy(),this._bindings.splice(h,1));return f},neverAny:function(){for(var c=this._bindings.length;c--;)this._bindings[c]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},emit:function(c){if(this.active){var f=Array.prototype.slice.call(arguments),g=this._bindings.length,h;if(this.memorize)this._prevParams=f;if(g){h= | ||
this._bindings.slice();this._shouldPropagate=!0;do g--;while(h[g]&&this._shouldPropagate&&h[g].execute(f)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.neverAny();delete this._bindings;delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"},constructor:i};var k=i;k.Signal=i;typeof define==="function"&&define.amd?define(function(){return k}):typeof module!=="undefined"&&module.exports?module.exports=k: | ||
m.signals=k})(this); |
{ | ||
"name" : "adverb-signals", | ||
"description" : "An event system based on JS-Signals.", | ||
"keywords" : ["js-signals", "signals", "pub/sub", "event", "publish", "subscribe", "observer", "adverb"], | ||
"homepage" : "https://github.com/sholladay/adverb-signals", | ||
"version" : "0.1.0", | ||
"main" : "dist/signals.js", | ||
"author" : { | ||
"name" : "Seth Holladay", | ||
"url" : "http://seth-holladay.com" | ||
}, | ||
"repository" : { | ||
"type" : "git", | ||
"url": "git@github.com:sholladay/adverb-signals.git" | ||
}, | ||
"bugs" : { | ||
"url" : "https://github.com/sholladay/adverb-signals/issues" | ||
}, | ||
"devDependencies" : { | ||
"jasmine-node" : "^1.14.5" | ||
}, | ||
"scripts" : { | ||
"test" : "jasmine-node test/spec" | ||
}, | ||
"directories" : { | ||
"doc" : "./dist/docs" | ||
}, | ||
"license": "MIT" | ||
"name": "adverb-signals", | ||
"description": "An event system based on JS-Signals.", | ||
"keywords": [ | ||
"js-signals", | ||
"signals", | ||
"pub/sub", | ||
"event", | ||
"publish", | ||
"subscribe", | ||
"observer", | ||
"adverb" | ||
], | ||
"homepage": "https://github.com/sholladay/adverb-signals", | ||
"version": "1.0.0", | ||
"main": "dist/signals.js", | ||
"author": { | ||
"name": "Seth Holladay", | ||
"url": "http://seth-holladay.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:sholladay/adverb-signals.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sholladay/adverb-signals/issues" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "^1.14.5" | ||
}, | ||
"scripts": { | ||
"test": "jasmine-node test/spec" | ||
}, | ||
"directories": { | ||
"doc": "./dist/docs" | ||
}, | ||
"license": "MIT" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
162356
645
0