Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reflux

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reflux - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

test/overridingEmitHooks.spec.js

2

bower.json
{
"name": "reflux",
"version": "0.1.11",
"version": "0.1.12",
"homepage": "https://github.com/spoike/reflux",

@@ -5,0 +5,0 @@ "authors": [

@@ -5,2 +5,6 @@ # Changelog

## v0.1.12
* Bug fixes. Check the [0.1.12 milestone page](https://github.com/spoike/refluxjs/issues?q=milestone%3A0.1.12+is%3Aclosed).
## v0.1.9, v0.1.10, v0.1.11

@@ -12,3 +16,7 @@

Update coming soon
* Added `Reflux.connect`, `Reflux.listenTo`, `listenToMany` conveniences. See [#63](https://github.com/spoike/refluxjs/pull/63) and [#75](https://github.com/spoike/refluxjs/pull/75)
* Stores may now use a `listenables` prop [#63](https://github.com/spoike/refluxjs/pull/63) to automatically register actions to callbacks
* `preEmit` may now map or transform the action payload by returning something. See [58](https://github.com/spoike/refluxjs/issues/58) and [#78](https://github.com/spoike/refluxjs/pull/78)
* Reflux now exposes a `keep` for easier introspection on actions and stores [#56](https://github.com/spoike/refluxjs/issues/56)
* Added mixin interfaces `ListenerMethods` and `PublisherMethods` making it possible for users to extend Reflux's actions and stores. See [#45](https://github.com/spoike/refluxjs/issues/45)

@@ -15,0 +23,0 @@ ## v0.1.7

@@ -550,3 +550,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Reflux=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

}
var me = this, cb = (key ? function(v){me.setState(_.object([key],[v]));} : this.setState);
var me = this, cb = (key === undefined ? this.setState : function(v){me.setState(_.object([key],[v]));});
this.listenTo(listenable,cb,cb);

@@ -553,0 +553,0 @@ },

@@ -1,1 +0,1 @@

!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.Reflux=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a,b,c){this.fn=a,this.context=b,this.once=c||!1}function d(){}d.prototype._events=void 0,d.prototype.listeners=function(a){if(!this._events||!this._events[a])return[];for(var b=0,c=this._events[a].length,d=[];c>b;b++)d.push(this._events[a][b].fn);return d},d.prototype.emit=function(a,b,c,d,e,f){if(!this._events||!this._events[a])return!1;var g,h,i,j=this._events[a],k=j.length,l=arguments.length,m=j[0];if(1===k){switch(m.once&&this.removeListener(a,m.fn,!0),l){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,b),!0;case 3:return m.fn.call(m.context,b,c),!0;case 4:return m.fn.call(m.context,b,c,d),!0;case 5:return m.fn.call(m.context,b,c,d,e),!0;case 6:return m.fn.call(m.context,b,c,d,e,f),!0}for(h=1,g=new Array(l-1);l>h;h++)g[h-1]=arguments[h];m.fn.apply(m.context,g)}else for(h=0;k>h;h++)switch(j[h].once&&this.removeListener(a,j[h].fn,!0),l){case 1:j[h].fn.call(j[h].context);break;case 2:j[h].fn.call(j[h].context,b);break;case 3:j[h].fn.call(j[h].context,b,c);break;default:if(!g)for(i=1,g=new Array(l-1);l>i;i++)g[i-1]=arguments[i];j[h].fn.apply(j[h].context,g)}return!0},d.prototype.on=function(a,b,d){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),this._events[a].push(new c(b,d||this)),this},d.prototype.once=function(a,b,d){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),this._events[a].push(new c(b,d||this,!0)),this},d.prototype.removeListener=function(a,b,c){if(!this._events||!this._events[a])return this;var d=this._events[a],e=[];if(b)for(var f=0,g=d.length;g>f;f++)d[f].fn!==b&&d[f].once!==c&&e.push(d[f]);return this._events[a]=e.length?e:null,this},d.prototype.removeAllListeners=function(a){return this._events?(a?this._events[a]=null:this._events={},this):this},d.prototype.off=d.prototype.removeListener,d.prototype.addListener=d.prototype.on,d.prototype.setMaxListeners=function(){return this},d.EventEmitter=d,d.EventEmitter2=d,d.EventEmitter3=d,"object"==typeof b&&b.exports&&(b.exports=d)},{}],2:[function(a,b,c){c.createdStores=[],c.createdActions=[],c.reset=function(){for(;c.createdStores.length;)c.createdStores.pop();for(;c.createdActions.length;)c.createdActions.pop()}},{}],3:[function(a,b){var c=a("./utils");b.exports={hasListener:function(a){for(var b,c=0;c<(this.subscriptions||[]).length;++c)if(b=this.subscriptions[c].listenable,b===a&&!a._isAction||b.hasListener&&b.hasListener(a))return!0;return!1},listenToMany:function(a){for(var b in a){var d=c.callbackName(b),e=this[d]?d:this[b]?b:void 0;e&&this.listenTo(a[b],e,this[d+"Default"]||this[e+"Default"]||e)}},validateListening:function(a){return a===this?"Listener is not able to listen to itself":c.isFunction(a.listen)?this.hasListener(a)?"Listener cannot listen to this listenable because of circular loop":void 0:a+" is missing a listen method"},listenTo:function(a,b,c){var d=this.validateListening(a),e=this;if(d)throw Error(d);this.fetchDefaultData(a,c),this.subscriptions||(this.subscriptions=[]);var f=a.listen(this[b]||b,this),g=function(b){f(),b||e.subscriptions.splice(e.subscriptions.indexOf(a),1)},h={stop:g,listenable:a};return this.subscriptions.push(h),h},stopListeningTo:function(a,b){for(var c=0;c<(this.subscriptions||[]).length;c++)if(this.subscriptions[c].listenable===a)return this.subscriptions[c].stop(b),!0;return!1},stopListeningToAll:function(){(this.subscriptions||[]).forEach(function(a){a.stop(!0)}),this.subscriptions=[]},fetchDefaultData:function(a,b){b=b&&this[b]||b;var d=this;c.isFunction(b)&&c.isFunction(a.getDefaultData)&&(data=a.getDefaultData(),data&&c.isFunction(data.then)?data.then(function(){b.apply(d,arguments)}):b.call(this,data))}}},{"./utils":13}],4:[function(a,b){var c=a("./utils"),d=a("./ListenerMethods");b.exports=c.extend({componentWillUnmount:d.stopListeningToAll},d)},{"./ListenerMethods":3,"./utils":13}],5:[function(a,b){var c=a("./utils");b.exports={preEmit:function(){},shouldEmit:function(){return!0},listen:function(a,b){var c=function(c){a.apply(b,c)},d=this;return this.emitter.addListener(this.eventLabel,c),function(){d.emitter.removeListener(d.eventLabel,c)}},trigger:function(){var a=arguments,b=this.preEmit.apply(this,a);a=void 0===b?a:c.isArguments(b)?b:[].concat(b),this.shouldEmit.apply(this,a)&&this.emitter.emit(this.eventLabel,a)},triggerAsync:function(){var a=arguments,b=this;c.nextTick(function(){b.trigger.apply(b,a)})}}},{"./utils":13}],6:[function(a,b){var c=a("./createAction"),d=Array.prototype.slice;b.exports=function(){function a(){g=new Array(i),h=new Array(i)}function b(a){return function(){g[a]=!0,h[a]=d.call(arguments),e()}}function e(){f()&&(j.apply(j,h),a())}function f(){for(var a=0;i>a;a++)if(!g[a])return!1;return!0}var g,h,i=arguments.length,j=c(),k=d.call(arguments);j._isAction=!1,j.hasListener=function(a){for(var b,c=0;c<k.length;++c)if(b=k[c],b===a&&!b._isAction||b.hasListener&&b.hasListener(a))return!0;return!1},a();for(var l=0;i>l;l++)arguments[l].listen(b(l),null);return j}},{"./createAction":8}],7:[function(a,b){var c=a("../src"),d=a("./utils");b.exports=function(a,b){return{componentDidMount:function(){for(var e in c.ListenerMethods)if(this[e]!==c.ListenerMethods[e]){if(this[e])throw"Can't have other property '"+e+"' when using Reflux.listenTo!";this[e]=c.ListenerMethods[e]}var f=this,g=b?function(a){f.setState(d.object([b],[a]))}:this.setState;this.listenTo(a,g,g)},componentWillUnmount:c.ListenerMixin.componentWillUnmount}}},{"../src":10,"./utils":13}],8:[function(a,b){var c=a("./utils"),d=a("../src"),e=a("./Keep");b.exports=function(a){a=a||{};var b=c.extend({eventLabel:"action",emitter:new c.EventEmitter,_isAction:!0},a,d.PublisherMethods,{preEmit:a.preEmit||d.PublisherMethods.preEmit,shouldEmit:a.shouldEmit||d.PublisherMethods.shouldEmit}),f=function(){b.triggerAsync.apply(b,arguments)};return c.extend(f,b),e.createdActions.push(f),f}},{"../src":10,"./Keep":2,"./utils":13}],9:[function(a,b){var c=a("./utils"),d=a("../src"),e=a("./Keep");b.exports=function(a){function b(){var a,b=0;if(this.subscriptions=[],this.emitter=new c.EventEmitter,this.eventLabel="change",this.init&&c.isFunction(this.init)&&this.init(),this.listenables)for(a=[].concat(this.listenables);b<a.length;b++)this.listenToMany(a[b])}a=a||{},c.extend(b.prototype,a,d.ListenerMethods,d.PublisherMethods,{preEmit:a.preEmit||d.PublisherMethods.preEmit,shouldEmit:a.shouldEmit||d.PublisherMethods.shouldEmit});var f=new b;return e.createdStores.push(f),f}},{"../src":10,"./Keep":2,"./utils":13}],10:[function(a,b,c){c.ListenerMethods=a("./ListenerMethods"),c.PublisherMethods=a("./PublisherMethods"),c.createAction=a("./createAction"),c.createStore=a("./createStore"),c.connect=a("./connect"),c.ListenerMixin=a("./ListenerMixin"),c.listenTo=a("./listenTo"),c.listenToMany=a("./listenToMany"),c.all=a("./all"),c.createActions=function(a){for(var b=0,d={};b<a.length;b++)d[a[b]]=c.createAction();return d},c.setEventEmitter=function(b){var c=a("./utils");c.EventEmitter=b},c.nextTick=function(b){var c=a("./utils");c.nextTick=b},c.__keep=a("./Keep")},{"./Keep":2,"./ListenerMethods":3,"./ListenerMixin":4,"./PublisherMethods":5,"./all":6,"./connect":7,"./createAction":8,"./createStore":9,"./listenTo":11,"./listenToMany":12,"./utils":13}],11:[function(a,b){var c=a("../src");b.exports=function(a,b,d){return{componentDidMount:function(){for(var e in c.ListenerMethods)if(this[e]!==c.ListenerMethods[e]){if(this[e])throw"Can't have other property '"+e+"' when using Reflux.listenTo!";this[e]=c.ListenerMethods[e]}this.listenTo(a,b,d)},componentWillUnmount:c.ListenerMethods.stopListeningToAll}}},{"../src":10}],12:[function(a,b){var c=a("../src");b.exports=function(a){return{componentDidMount:function(){for(var b in c.ListenerMethods)if(this[b]!==c.ListenerMethods[b]){if(this[b])throw"Can't have other property '"+b+"' when using Reflux.listenToMany!";this[b]=c.ListenerMethods[b]}this.listenToMany(a)},componentWillUnmount:c.ListenerMethods.stopListeningToAll}}},{"../src":10}],13:[function(a,b,c){var d=c.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a};c.extend=function(a){if(!d(a))return a;for(var b,c,e=1,f=arguments.length;f>e;e++){b=arguments[e];for(c in b)a[c]=b[c]}return a},c.isFunction=function(a){return"function"==typeof a},c.EventEmitter=a("eventemitter3"),c.nextTick=function(a){setTimeout(a,0)},c.callbackName=function(a){return"on"+a.charAt(0).toUpperCase()+a.slice(1)},c.object=function(a,b){for(var c={},d=0;d<a.length;d++)c[a[d]]=b[d];return c},c.isArguments=function(a){return a&&"object"==typeof a&&"number"==typeof a.length&&("[object Arguments]"===toString.call(a)||hasOwnProperty.call(a,"callee"&&!propertyIsEnumerable.call(a,"callee")))||!1}},{eventemitter3:1}]},{},[10])(10)});
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.Reflux=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a,b,c){this.fn=a,this.context=b,this.once=c||!1}function d(){}d.prototype._events=void 0,d.prototype.listeners=function(a){if(!this._events||!this._events[a])return[];for(var b=0,c=this._events[a].length,d=[];c>b;b++)d.push(this._events[a][b].fn);return d},d.prototype.emit=function(a,b,c,d,e,f){if(!this._events||!this._events[a])return!1;var g,h,i,j=this._events[a],k=j.length,l=arguments.length,m=j[0];if(1===k){switch(m.once&&this.removeListener(a,m.fn,!0),l){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,b),!0;case 3:return m.fn.call(m.context,b,c),!0;case 4:return m.fn.call(m.context,b,c,d),!0;case 5:return m.fn.call(m.context,b,c,d,e),!0;case 6:return m.fn.call(m.context,b,c,d,e,f),!0}for(h=1,g=new Array(l-1);l>h;h++)g[h-1]=arguments[h];m.fn.apply(m.context,g)}else for(h=0;k>h;h++)switch(j[h].once&&this.removeListener(a,j[h].fn,!0),l){case 1:j[h].fn.call(j[h].context);break;case 2:j[h].fn.call(j[h].context,b);break;case 3:j[h].fn.call(j[h].context,b,c);break;default:if(!g)for(i=1,g=new Array(l-1);l>i;i++)g[i-1]=arguments[i];j[h].fn.apply(j[h].context,g)}return!0},d.prototype.on=function(a,b,d){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),this._events[a].push(new c(b,d||this)),this},d.prototype.once=function(a,b,d){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),this._events[a].push(new c(b,d||this,!0)),this},d.prototype.removeListener=function(a,b,c){if(!this._events||!this._events[a])return this;var d=this._events[a],e=[];if(b)for(var f=0,g=d.length;g>f;f++)d[f].fn!==b&&d[f].once!==c&&e.push(d[f]);return this._events[a]=e.length?e:null,this},d.prototype.removeAllListeners=function(a){return this._events?(a?this._events[a]=null:this._events={},this):this},d.prototype.off=d.prototype.removeListener,d.prototype.addListener=d.prototype.on,d.prototype.setMaxListeners=function(){return this},d.EventEmitter=d,d.EventEmitter2=d,d.EventEmitter3=d,"object"==typeof b&&b.exports&&(b.exports=d)},{}],2:[function(a,b,c){c.createdStores=[],c.createdActions=[],c.reset=function(){for(;c.createdStores.length;)c.createdStores.pop();for(;c.createdActions.length;)c.createdActions.pop()}},{}],3:[function(a,b){var c=a("./utils");b.exports={hasListener:function(a){for(var b,c=0;c<(this.subscriptions||[]).length;++c)if(b=this.subscriptions[c].listenable,b===a&&!a._isAction||b.hasListener&&b.hasListener(a))return!0;return!1},listenToMany:function(a){for(var b in a){var d=c.callbackName(b),e=this[d]?d:this[b]?b:void 0;e&&this.listenTo(a[b],e,this[d+"Default"]||this[e+"Default"]||e)}},validateListening:function(a){return a===this?"Listener is not able to listen to itself":c.isFunction(a.listen)?this.hasListener(a)?"Listener cannot listen to this listenable because of circular loop":void 0:a+" is missing a listen method"},listenTo:function(a,b,c){var d=this.validateListening(a),e=this;if(d)throw Error(d);this.fetchDefaultData(a,c),this.subscriptions||(this.subscriptions=[]);var f=a.listen(this[b]||b,this),g=function(b){f(),b||e.subscriptions.splice(e.subscriptions.indexOf(a),1)},h={stop:g,listenable:a};return this.subscriptions.push(h),h},stopListeningTo:function(a,b){for(var c=0;c<(this.subscriptions||[]).length;c++)if(this.subscriptions[c].listenable===a)return this.subscriptions[c].stop(b),!0;return!1},stopListeningToAll:function(){(this.subscriptions||[]).forEach(function(a){a.stop(!0)}),this.subscriptions=[]},fetchDefaultData:function(a,b){b=b&&this[b]||b;var d=this;c.isFunction(b)&&c.isFunction(a.getDefaultData)&&(data=a.getDefaultData(),data&&c.isFunction(data.then)?data.then(function(){b.apply(d,arguments)}):b.call(this,data))}}},{"./utils":13}],4:[function(a,b){var c=a("./utils"),d=a("./ListenerMethods");b.exports=c.extend({componentWillUnmount:d.stopListeningToAll},d)},{"./ListenerMethods":3,"./utils":13}],5:[function(a,b){var c=a("./utils");b.exports={preEmit:function(){},shouldEmit:function(){return!0},listen:function(a,b){var c=function(c){a.apply(b,c)},d=this;return this.emitter.addListener(this.eventLabel,c),function(){d.emitter.removeListener(d.eventLabel,c)}},trigger:function(){var a=arguments,b=this.preEmit.apply(this,a);a=void 0===b?a:c.isArguments(b)?b:[].concat(b),this.shouldEmit.apply(this,a)&&this.emitter.emit(this.eventLabel,a)},triggerAsync:function(){var a=arguments,b=this;c.nextTick(function(){b.trigger.apply(b,a)})}}},{"./utils":13}],6:[function(a,b){var c=a("./createAction"),d=Array.prototype.slice;b.exports=function(){function a(){g=new Array(i),h=new Array(i)}function b(a){return function(){g[a]=!0,h[a]=d.call(arguments),e()}}function e(){f()&&(j.apply(j,h),a())}function f(){for(var a=0;i>a;a++)if(!g[a])return!1;return!0}var g,h,i=arguments.length,j=c(),k=d.call(arguments);j._isAction=!1,j.hasListener=function(a){for(var b,c=0;c<k.length;++c)if(b=k[c],b===a&&!b._isAction||b.hasListener&&b.hasListener(a))return!0;return!1},a();for(var l=0;i>l;l++)arguments[l].listen(b(l),null);return j}},{"./createAction":8}],7:[function(a,b){var c=a("../src"),d=a("./utils");b.exports=function(a,b){return{componentDidMount:function(){for(var e in c.ListenerMethods)if(this[e]!==c.ListenerMethods[e]){if(this[e])throw"Can't have other property '"+e+"' when using Reflux.listenTo!";this[e]=c.ListenerMethods[e]}var f=this,g=void 0===b?this.setState:function(a){f.setState(d.object([b],[a]))};this.listenTo(a,g,g)},componentWillUnmount:c.ListenerMixin.componentWillUnmount}}},{"../src":10,"./utils":13}],8:[function(a,b){var c=a("./utils"),d=a("../src"),e=a("./Keep");b.exports=function(a){a=a||{};var b=c.extend({eventLabel:"action",emitter:new c.EventEmitter,_isAction:!0},a,d.PublisherMethods,{preEmit:a.preEmit||d.PublisherMethods.preEmit,shouldEmit:a.shouldEmit||d.PublisherMethods.shouldEmit}),f=function(){b.triggerAsync.apply(b,arguments)};return c.extend(f,b),e.createdActions.push(f),f}},{"../src":10,"./Keep":2,"./utils":13}],9:[function(a,b){var c=a("./utils"),d=a("../src"),e=a("./Keep");b.exports=function(a){function b(){var a,b=0;if(this.subscriptions=[],this.emitter=new c.EventEmitter,this.eventLabel="change",this.init&&c.isFunction(this.init)&&this.init(),this.listenables)for(a=[].concat(this.listenables);b<a.length;b++)this.listenToMany(a[b])}a=a||{},c.extend(b.prototype,a,d.ListenerMethods,d.PublisherMethods,{preEmit:a.preEmit||d.PublisherMethods.preEmit,shouldEmit:a.shouldEmit||d.PublisherMethods.shouldEmit});var f=new b;return e.createdStores.push(f),f}},{"../src":10,"./Keep":2,"./utils":13}],10:[function(a,b,c){c.ListenerMethods=a("./ListenerMethods"),c.PublisherMethods=a("./PublisherMethods"),c.createAction=a("./createAction"),c.createStore=a("./createStore"),c.connect=a("./connect"),c.ListenerMixin=a("./ListenerMixin"),c.listenTo=a("./listenTo"),c.listenToMany=a("./listenToMany"),c.all=a("./all"),c.createActions=function(a){for(var b=0,d={};b<a.length;b++)d[a[b]]=c.createAction();return d},c.setEventEmitter=function(b){var c=a("./utils");c.EventEmitter=b},c.nextTick=function(b){var c=a("./utils");c.nextTick=b},c.__keep=a("./Keep")},{"./Keep":2,"./ListenerMethods":3,"./ListenerMixin":4,"./PublisherMethods":5,"./all":6,"./connect":7,"./createAction":8,"./createStore":9,"./listenTo":11,"./listenToMany":12,"./utils":13}],11:[function(a,b){var c=a("../src");b.exports=function(a,b,d){return{componentDidMount:function(){for(var e in c.ListenerMethods)if(this[e]!==c.ListenerMethods[e]){if(this[e])throw"Can't have other property '"+e+"' when using Reflux.listenTo!";this[e]=c.ListenerMethods[e]}this.listenTo(a,b,d)},componentWillUnmount:c.ListenerMethods.stopListeningToAll}}},{"../src":10}],12:[function(a,b){var c=a("../src");b.exports=function(a){return{componentDidMount:function(){for(var b in c.ListenerMethods)if(this[b]!==c.ListenerMethods[b]){if(this[b])throw"Can't have other property '"+b+"' when using Reflux.listenToMany!";this[b]=c.ListenerMethods[b]}this.listenToMany(a)},componentWillUnmount:c.ListenerMethods.stopListeningToAll}}},{"../src":10}],13:[function(a,b,c){var d=c.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a};c.extend=function(a){if(!d(a))return a;for(var b,c,e=1,f=arguments.length;f>e;e++){b=arguments[e];for(c in b)a[c]=b[c]}return a},c.isFunction=function(a){return"function"==typeof a},c.EventEmitter=a("eventemitter3"),c.nextTick=function(a){setTimeout(a,0)},c.callbackName=function(a){return"on"+a.charAt(0).toUpperCase()+a.slice(1)},c.object=function(a,b){for(var c={},d=0;d<a.length;d++)c[a[d]]=b[d];return c},c.isArguments=function(a){return a&&"object"==typeof a&&"number"==typeof a.length&&("[object Arguments]"===toString.call(a)||hasOwnProperty.call(a,"callee"&&!propertyIsEnumerable.call(a,"callee")))||!1}},{eventemitter3:1}]},{},[10])(10)});
{
"name": "reflux",
"version": "0.1.11",
"version": "0.1.12",
"description": "A simple library for uni-directional dataflow application architecture inspired by ReactJS Flux",

@@ -35,3 +35,3 @@ "main": "src/index.js",

"karma-commonjs": "0.0.11",
"karma": "^0.12.23",
"karma": "0.12.23",
"karma-mocha": "^0.1.9",

@@ -38,0 +38,0 @@ "karma-phantomjs-launcher": "^0.1.4",

@@ -171,4 +171,4 @@ # RefluxJS

init: function() {
this.listenTo(actions.fireBall,this.fireBall);
this.listenTo(actions.magicMissile,this.magicMissile);
this.listenTo(actions.fireBall,this.onFireBall);
this.listenTo(actions.magicMissile,this.onMagicMissile);
},

@@ -191,3 +191,3 @@ onFireBall: function(){

init: function() {
this.listenToAll(actions);
this.listenToMany(actions);
},

@@ -194,0 +194,0 @@ onFireBall: function(){

@@ -1,5 +0,3 @@

var createAction = require('./createAction');
var createStore = require('./createStore');
var slice = Array.prototype.slice;
/**

@@ -9,79 +7,15 @@ * Track a set of Actions and Stores. Use Reflux.all if you need to handle

*
* @param {...Action|Store} listenables Actions and Stores that should be
* @param {...Publishers} publishers Publishers that should be
* tracked.
* @returns {Action} An action which tracks the provided Actions and Stores.
* The action will emit once all of the provided listenables have emitted at
* @returns {Store} A store which listens to the provided Publishers.
* The store will emit once all of the provided publishers have emitted at
* least once.
*/
module.exports = function(/* listenables... */) {
var numberOfListenables = arguments.length,
// create a new array of the expected size. The initial
// values will be falsy, which is fine for us.
// Once each item in the array is truthy, the callback can be called
listenablesEmitted,
// these arguments will be used to *apply* the action.
args,
// this action combines all the listenables
action = createAction(),
// the original listenables
listenables = slice.call(arguments);
action._isAction = false;
action.hasListener = function(listenable) {
var i = 0, listener;
for (; i < listenables.length; ++i) {
listener = listenables[i];
if ((listener === listenable && !listener._isAction) || listener.hasListener && listener.hasListener(listenable)) {
return true;
}
var listenables = Array.prototype.slice.call(arguments);
return createStore({
init: function(){
this.listenToAggregate.apply(this,listenables.concat("trigger"));
}
return false;
};
reset();
for (var i = 0; i < numberOfListenables; i++) {
arguments[i].listen(newListener(i), null);
}
return action;
function reset() {
listenablesEmitted = new Array(numberOfListenables);
args = new Array(numberOfListenables);
}
function newListener(i) {
return function() {
listenablesEmitted[i] = true;
// Reflux users should not need to care about Array and arguments
// differences. This makes sure that they get the expected Array
// interface
args[i] = slice.call(arguments);
emitWhenAllListenablesEmitted();
};
}
function emitWhenAllListenablesEmitted() {
if (didAllListenablesEmit()) {
action.apply(action, args);
reset();
}
}
function didAllListenablesEmit() {
// reduce cannot be used because it only iterates over *present*
// elements in the array. Initially the Array doesn't contain
// elements. For this reason the usage of reduce would always indicate
// that all listenables emitted.
for (var i = 0; i < numberOfListenables; i++) {
if (!listenablesEmitted[i]) {
return false;
}
}
return true;
}
});
};

@@ -15,3 +15,3 @@ var Reflux = require('../src'),

}
var me = this, cb = (key ? function(v){me.setState(_.object([key],[v]));} : this.setState);
var me = this, cb = (key === undefined ? this.setState : function(v){me.setState(_.object([key],[v]));});
this.listenTo(listenable,cb,cb);

@@ -18,0 +18,0 @@ },

@@ -19,3 +19,3 @@ var _ = require('./utils'),

emitter: new _.EventEmitter(),
_isAction: true,
_isAction: true
},definition,Reflux.PublisherMethods,{

@@ -27,3 +27,3 @@ preEmit: definition.preEmit || Reflux.PublisherMethods.preEmit,

var functor = function() {
context.triggerAsync.apply(context, arguments);
functor.triggerAsync.apply(functor, arguments);
};

@@ -30,0 +30,0 @@

@@ -1,2 +0,3 @@

var _ = require('./utils');
var _ = require('./utils'),
slice = Array.prototype.slice;

@@ -138,4 +139,60 @@ /**

}
},
/**
* The callback will be called once all listenables have triggered at least once.
* @param {...Publishers} publishers Publishers that should be tracked.
* @param {Function|String} callback The method to call when all publishers have emitted
*/
listenToAggregate: function(/* listenables... , callback */){
var listenables = slice.call(arguments),
callback = listenables.pop(),
numberOfListenables = listenables.length,
listener = this,
listenablesEmitted,
args;
for (var i = 0; i < numberOfListenables; i++) {
this.listenTo(listenables[i],newListener(i));
}
reset();
// ---- internal aggregation functions ----
function reset() {
listenablesEmitted = new Array(numberOfListenables);
args = new Array(numberOfListenables);
}
function newListener(i) {
return function() {
listenablesEmitted[i] = true;
// Reflux users should not need to care about Array and arguments
// differences. This makes sure that they get the expected Array
// interface
args[i] = slice.call(arguments);
emitWhenAllListenablesEmitted();
};
}
function emitWhenAllListenablesEmitted() {
if (didAllListenablesEmit()) {
(listener[callback]||callback).apply(listener,args);
reset();
}
}
function didAllListenablesEmit() {
// reduce cannot be used because it only iterates over *present*
// elements in the array. Initially the Array doesn't contain
// elements. For this reason the usage of reduce would always indicate
// that all listenables emitted.
for (var i = 0; i < numberOfListenables; i++) {
if (!listenablesEmitted[i]) {
return false;
}
}
return true;
}
}
};

@@ -41,3 +41,27 @@ var chai = require('chai'),

it('can also be created using listener method', function() {
var all = Reflux.createStore({
init: function(){
this.listenToAggregate(action1,action2,action3,this.trigger);
}
});
var promise = Q.Promise(function(resolve) {
all.listen(function() {
resolve(Array.prototype.slice.call(arguments, 0));
});
});
action1('a', 'x');
action2('b', 'y');
action3('c', 'z');
return assert.eventually.deepEqual(promise, [
['a', 'x'],
['b', 'y'],
['c', 'z']
]);
});
it('should not emit when only one listenable emits', function(done) {

@@ -44,0 +68,0 @@ var called = false;

@@ -74,2 +74,14 @@ var assert = require('chai').assert,

});
describe("when calling with falsy key",function(){
var triggerdata = "TRIGGERDATA",
key = 0,
listenable = {listen: sinon.spy()},
context = {setState: sinon.spy()},
result = _.extend(context,connect(listenable,key));
result.componentDidMount();
it("should send listenable callback which calls setState correctly",function(){
listenable.listen.firstCall.args[0](triggerdata);
assert.deepEqual([_.object([key],[triggerdata])],context.setState.firstCall.args);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc