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.1 to 0.1.2

src/ListenerMixin.js

2

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

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

!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){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
/**
* Minimal EventEmitter interface that is molded against the Node.js
* EventEmitter interface.
*
* @constructor
* @api public
*/
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
this._events = {};
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
/**
* Return a list of assigned event listeners.
*
* @param {String} event The events that should be listed.
* @returns {Array}
* @api public
*/
EventEmitter.prototype.listeners = function listeners(event) {
return Array.apply(this, this._events[event] || []);
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
/**
* Emit an event to all registered event listeners.
*
* @param {String} event The name of the event.
* @returns {Boolean} Indication if we've emitted an event.
* @api public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
if (!this._events || !this._events[event]) return false;
if (!this._events)
this._events = {};
var listeners = this._events[event]
, length = listeners.length
, len = arguments.length
, fn = listeners[0]
, args
, i;
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
throw TypeError('Uncaught, unspecified "error" event.');
}
return false;
}
}
if (1 === length) {
if (fn.__EE3_once) this.removeListener(event, fn);
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
switch (len) {
case 1:
handler.call(this);
break;
fn.call(fn.__EE3_context || this);
break;
case 2:
handler.call(this, arguments[1]);
break;
fn.call(fn.__EE3_context || this, a1);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
fn.call(fn.__EE3_context || this, a1, a2);
break;
case 4:
fn.call(fn.__EE3_context || this, a1, a2, a3);
break;
case 5:
fn.call(fn.__EE3_context || this, a1, a2, a3, a4);
break;
case 6:
fn.call(fn.__EE3_context || this, a1, a2, a3, a4, a5);
break;
default:
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
for (i = 1, args = new Array(len -1); i < len; i++) {
args[i - 1] = arguments[i];
handler.apply(this, args);
}
fn.apply(fn.__EE3_context || this, args);
}
} else if (isObject(handler)) {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
} else {
for (i = 1, args = new Array(len -1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
for (i = 0; i < length; fn = listeners[++i]) {
if (fn.__EE3_once) this.removeListener(event, fn);
fn.apply(fn.__EE3_context || this, args);
}
}

@@ -108,72 +87,57 @@

EventEmitter.prototype.addListener = function(type, listener) {
var m;
/**
* Register a new EventListener for the given event.
*
* @param {String} event Name of the event.
* @param {Functon} fn Callback function.
* @param {Mixed} context The context of the function.
* @api public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
if (!this._events) this._events = {};
if (!this._events[event]) this._events[event] = [];
if (!isFunction(listener))
throw TypeError('listener must be a function');
fn.__EE3_context = context;
this._events[event].push(fn);
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
var m;
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
/**
* Add an EventListener that's only called once.
*
* @param {String} event Name of the event.
* @param {Function} fn Callback function.
* @param {Mixed} context The context of the function.
* @api public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
fn.__EE3_once = true;
return this.on(event, fn, context);
};
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
/**
* Remove event listeners.
*
* @param {String} event The event we want to remove.
* @param {Function} fn The listener that we need to find.
* @api public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn) {
if (!this._events || !this._events[event]) return this;
var fired = false;
var listeners = this._events[event]
, events = [];
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
for (var i = 0, length = listeners.length; i < length; i++) {
if (fn && listeners[i] !== fn) {
events.push(listeners[i]);
}
}
g.listener = listener;
this.on(type, g);
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) this._events[event] = events;
else this._events[event] = null;

@@ -183,129 +147,76 @@ return this;

// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
/**
* Remove all listeners or only the listeners for the specified event.
*
* @param {String} event The event want to remove all listeners for.
* @api public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
if (!this._events) return this;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (event) this._events[event] = null;
else this._events = {};
if (!this._events || !this._events[type])
return this;
return this;
};
list = this._events[type];
length = list.length;
position = -1;
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
//
// This function doesn't apply anymore.
//
EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
//
// Expose the module.
//
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.EventEmitter2 = EventEmitter;
EventEmitter.EventEmitter3 = EventEmitter;
if (!this._events)
return this;
try { module.exports = EventEmitter; }
catch (e) {}
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
},{}],2:[function(_dereq_,module,exports){
module.exports = {
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
/**
* Set up the mixin before the initial rendering occurs. Event listeners
* and callbacks should be registered once the component successfully
* mounted (as described in the React docs).
*/
componentWillMount: function() {
this.subscriptions = [];
},
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
/**
* Subscribes the given callback for action triggered
*
* @param {Action|Store} listenable An Action or Store that should be
* listened to.
* @param {Function} callback The callback to register as event handler
*/
listenTo: function(listenable, callback) {
var unsubscribe = listenable.listen(callback, this);
this.subscriptions.push(unsubscribe);
},
return this;
componentWillUnmount: function() {
this.subscriptions.forEach(function(unsubscribe) {
unsubscribe();
});
this.subscriptions = [];
}
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
},{}],3:[function(_dereq_,module,exports){
var _ = _dereq_('./utils');
EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
},{}],2:[function(_dereq_,module,exports){
var EventEmitter = _dereq_('events').EventEmitter;
/**

@@ -316,3 +227,3 @@ * Creates an action functor object

var action = new EventEmitter(),
var action = new _.EventEmitter(),
eventLabel = "action",

@@ -347,5 +258,4 @@ functor;

},{"events":1}],3:[function(_dereq_,module,exports){
var EventEmitter = _dereq_('events').EventEmitter,
_ = _dereq_('./utils');
},{"./utils":6}],4:[function(_dereq_,module,exports){
var _ = _dereq_('./utils');

@@ -358,3 +268,3 @@ /**

module.exports = function(definition) {
var store = new EventEmitter(),
var store = new _.EventEmitter(),
eventLabel = "change";

@@ -392,15 +302,23 @@

},{"./utils":5,"events":1}],4:[function(_dereq_,module,exports){
var createAction = exports.createAction = _dereq_('./createAction');
},{"./utils":6}],5:[function(_dereq_,module,exports){
exports.createAction = _dereq_('./createAction');
exports.createStore = _dereq_('./createStore');
exports.ListenerMixin = _dereq_('./ListenerMixin');
exports.createActions = function(actionNames) {
var i = 0, actions = {};
for (; i < actionNames.length; i++) {
actions[actionNames[i]] = createAction();
actions[actionNames[i]] = exports.createAction();
}
return actions;
};
},{"./createAction":2,"./createStore":3}],5:[function(_dereq_,module,exports){
exports.setEventEmitter = function(ctx) {
var _ = _dereq_('./utils');
_.EventEmitter = ctx;
};
},{"./ListenerMixin":2,"./createAction":3,"./createStore":4,"./utils":6}],6:[function(_dereq_,module,exports){
/*

@@ -432,4 +350,5 @@ * isObject, extend and isFunction are taken from undescore/lodash in

},{}]},{},[4])
(4)
module.exports.EventEmitter = _dereq_('eventemitter3');
},{"eventemitter3":1}]},{},[5])
(5)
});

@@ -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){function c(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function d(a){return"function"==typeof a}function e(a){return"number"==typeof a}function f(a){return"object"==typeof a&&null!==a}function g(a){return void 0===a}b.exports=c,c.EventEmitter=c,c.prototype._events=void 0,c.prototype._maxListeners=void 0,c.defaultMaxListeners=10,c.prototype.setMaxListeners=function(a){if(!e(a)||0>a||isNaN(a))throw TypeError("n must be a positive number");return this._maxListeners=a,this},c.prototype.emit=function(a){var b,c,e,h,i,j;if(this._events||(this._events={}),"error"===a&&(!this._events.error||f(this._events.error)&&!this._events.error.length))throw b=arguments[1],b instanceof Error?b:TypeError('Uncaught, unspecified "error" event.');if(c=this._events[a],g(c))return!1;if(d(c))switch(arguments.length){case 1:c.call(this);break;case 2:c.call(this,arguments[1]);break;case 3:c.call(this,arguments[1],arguments[2]);break;default:for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];c.apply(this,h)}else if(f(c)){for(e=arguments.length,h=new Array(e-1),i=1;e>i;i++)h[i-1]=arguments[i];for(j=c.slice(),e=j.length,i=0;e>i;i++)j[i].apply(this,h)}return!0},c.prototype.addListener=function(a,b){var e;if(!d(b))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",a,d(b.listener)?b.listener:b),this._events[a]?f(this._events[a])?this._events[a].push(b):this._events[a]=[this._events[a],b]:this._events[a]=b,f(this._events[a])&&!this._events[a].warned){var e;e=g(this._maxListeners)?c.defaultMaxListeners:this._maxListeners,e&&e>0&&this._events[a].length>e&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),"function"==typeof console.trace&&console.trace())}return this},c.prototype.on=c.prototype.addListener,c.prototype.once=function(a,b){function c(){this.removeListener(a,c),e||(e=!0,b.apply(this,arguments))}if(!d(b))throw TypeError("listener must be a function");var e=!1;return c.listener=b,this.on(a,c),this},c.prototype.removeListener=function(a,b){var c,e,g,h;if(!d(b))throw TypeError("listener must be a function");if(!this._events||!this._events[a])return this;if(c=this._events[a],g=c.length,e=-1,c===b||d(c.listener)&&c.listener===b)delete this._events[a],this._events.removeListener&&this.emit("removeListener",a,b);else if(f(c)){for(h=g;h-->0;)if(c[h]===b||c[h].listener&&c[h].listener===b){e=h;break}if(0>e)return this;1===c.length?(c.length=0,delete this._events[a]):c.splice(e,1),this._events.removeListener&&this.emit("removeListener",a,b)}return this},c.prototype.removeAllListeners=function(a){var b,c;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[a]&&delete this._events[a],this;if(0===arguments.length){for(b in this._events)"removeListener"!==b&&this.removeAllListeners(b);return this.removeAllListeners("removeListener"),this._events={},this}if(c=this._events[a],d(c))this.removeListener(a,c);else for(;c.length;)this.removeListener(a,c[c.length-1]);return delete this._events[a],this},c.prototype.listeners=function(a){var b;return b=this._events&&this._events[a]?d(this._events[a])?[this._events[a]]:this._events[a].slice():[]},c.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?d(a._events[b])?1:a._events[b].length:0}},{}],2:[function(a,b){var c=a("events").EventEmitter;b.exports=function(){var a,b=new c,d="action";return a=function(){b.emit(d,Array.prototype.slice.call(arguments,0))},a.listen=function(a,c){var e=function(b){a.apply(c,b)};return b.addListener(d,e),function(){b.removeListener(d,e)}},a}},{events:1}],3:[function(a,b){var c=a("events").EventEmitter,d=a("./utils");b.exports=function(a){function b(){this.init&&d.isFunction(this.init)&&this.init()}var e=new c,f="change";return d.extend(b.prototype,a),b.prototype.listenTo=function(a,b){if(!d.isFunction(a.listen))throw new TypeError(a+" is missing a listen method");return a.listen(b,this)},b.prototype.listen=function(a,b){var c=function(c){a.apply(b,c)};return e.addListener(f,c),function(){e.removeListener(f,c)}},b.prototype.trigger=function(){var a=Array.prototype.slice.call(arguments,0);e.emit(f,a)},new b}},{"./utils":5,events:1}],4:[function(a,b,c){var d=c.createAction=a("./createAction");c.createStore=a("./createStore"),c.createActions=function(a){for(var b=0,c={};b<a.length;b++)c[a[b]]=d();return c}},{"./createAction":2,"./createStore":3}],5:[function(a,b){var c=b.exports.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a};b.exports.extend=function(a){if(!c(a))return a;for(var b,d,e=1,f=arguments.length;f>e;e++){b=arguments[e];for(d in b)a[d]=b[d]}return a},b.exports.isFunction=function(a){return"function"==typeof a}},{}]},{},[4])(4)});
!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(){this._events={}}c.prototype.listeners=function(a){return Array.apply(this,this._events[a]||[])},c.prototype.emit=function(a,b,c,d,e,f){if(!this._events||!this._events[a])return!1;var g,h,i=this._events[a],j=i.length,k=arguments.length,l=i[0];if(1===j)switch(l.__EE3_once&&this.removeListener(a,l),k){case 1:l.call(l.__EE3_context||this);break;case 2:l.call(l.__EE3_context||this,b);break;case 3:l.call(l.__EE3_context||this,b,c);break;case 4:l.call(l.__EE3_context||this,b,c,d);break;case 5:l.call(l.__EE3_context||this,b,c,d,e);break;case 6:l.call(l.__EE3_context||this,b,c,d,e,f);break;default:for(h=1,g=new Array(k-1);k>h;h++)g[h-1]=arguments[h];l.apply(l.__EE3_context||this,g)}else{for(h=1,g=new Array(k-1);k>h;h++)g[h-1]=arguments[h];for(h=0;j>h;l=i[++h])l.__EE3_once&&this.removeListener(a,l),l.apply(l.__EE3_context||this,g)}return!0},c.prototype.on=function(a,b,c){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),b.__EE3_context=c,this._events[a].push(b),this},c.prototype.once=function(a,b,c){return b.__EE3_once=!0,this.on(a,b,c)},c.prototype.removeListener=function(a,b){if(!this._events||!this._events[a])return this;for(var c=this._events[a],d=[],e=0,f=c.length;f>e;e++)b&&c[e]!==b&&d.push(c[e]);return this._events[a]=d.length?d:null,this},c.prototype.removeAllListeners=function(a){return this._events?(a?this._events[a]=null:this._events={},this):this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prototype.setMaxListeners=function(){return this},c.EventEmitter=c,c.EventEmitter2=c,c.EventEmitter3=c;try{b.exports=c}catch(d){}},{}],2:[function(a,b){b.exports={componentWillMount:function(){this.subscriptions=[]},listenTo:function(a,b){var c=a.listen(b,this);this.subscriptions.push(c)},componentWillUnmount:function(){this.subscriptions.forEach(function(a){a()}),this.subscriptions=[]}}},{}],3:[function(a,b){var c=a("./utils");b.exports=function(){var a,b=new c.EventEmitter,d="action";return a=function(){b.emit(d,Array.prototype.slice.call(arguments,0))},a.listen=function(a,c){var e=function(b){a.apply(c,b)};return b.addListener(d,e),function(){b.removeListener(d,e)}},a}},{"./utils":6}],4:[function(a,b){var c=a("./utils");b.exports=function(a){function b(){this.init&&c.isFunction(this.init)&&this.init()}var d=new c.EventEmitter,e="change";return c.extend(b.prototype,a),b.prototype.listenTo=function(a,b){if(!c.isFunction(a.listen))throw new TypeError(a+" is missing a listen method");return a.listen(b,this)},b.prototype.listen=function(a,b){var c=function(c){a.apply(b,c)};return d.addListener(e,c),function(){d.removeListener(e,c)}},b.prototype.trigger=function(){var a=Array.prototype.slice.call(arguments,0);d.emit(e,a)},new b}},{"./utils":6}],5:[function(a,b,c){c.createAction=a("./createAction"),c.createStore=a("./createStore"),c.ListenerMixin=a("./ListenerMixin"),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}},{"./ListenerMixin":2,"./createAction":3,"./createStore":4,"./utils":6}],6:[function(a,b){var c=b.exports.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a};b.exports.extend=function(a){if(!c(a))return a;for(var b,d,e=1,f=arguments.length;f>e;e++){b=arguments[e];for(d in b)a[d]=b[d]}return a},b.exports.isFunction=function(a){return"function"==typeof a},b.exports.EventEmitter=a("eventemitter3")},{eventemitter3:1}]},{},[5])(5)});
{
"name": "reflux",
"version": "0.1.1",
"version": "0.1.2",
"description": "A simple library for uni-directional dataflow application architecture inspired by ReactJS Flux",

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

"browserify-shim": {},
"dependencies": {},
"dependencies": {
"eventemitter3": "^0.1.2"
},
"devDependencies": {

@@ -24,0 +26,0 @@ "browserify": "^4.2.0",

@@ -7,3 +7,3 @@ # Reflux

You can read an overview of Flux [here](http://facebook.github.io/react/docs/flux-overview.html), however the gist of it is to introduce a more functional programming style architecture by eschewing MVC like pattern and adopting a single data flow pattern.
You can read an overview of Flux [here](http://facebook.github.io/react/docs/flux-overview.html), however the gist of it is to introduce a more functional programming style architecture by eschewing MVC like pattern and adopting a single data flow pattern.

@@ -137,3 +137,3 @@ ```

#### ReactJS example
#### React component example

@@ -162,2 +162,26 @@ Register your component to listen for changes in your data stores, preferably in the `componentDidMount` [lifecycle method](http://facebook.github.io/react/docs/component-specs.html) and unregister in the `componentWillUnmount`, like this:

#### Convenience mixin for React
You always need to unsubscribe components from observed actions and stores upon
unmounting. To simplify this process you can use [mixins in React](http://facebook.github.io/react/docs/reusable-components.html#mixins). There is a convenience mixin available at `Reflux.ListenerMixin`.
```javascript
var Status = React.createClass({
mixins: [Reflux.ListenerMixin],
onStatusChange: function(status) {
this.setState({
currentStatus: status
});
},
componentDidMount: function() {
this.listenTo(statusStore, this.onStatusChange);
},
render: function() {
// render specifics
}
});
```
The mixin provides the `listenTo` method for the React component, that works much like the one found in the Reflux's stores, and handles the listeners during mount and unmount for you.
### Listening to changes in other data stores (aggregate data stores)

@@ -190,8 +214,20 @@

```
### Switching EventEmitter
Don't like to use the EventEmitter provided? You can switch to another one, such as NodeJS's own like this:
## License
```javascript
// Do this before creating actions or stores
Reflux.setEventEmitter(require('events').EventEmitter);
```
## Colophon
[List of contributors](https://github.com/spoike/reflux/graphs/contributors) is available on Github.
This project is licensed under [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause). Copyright (c) 2014, Mikael Brassman.
For more information about the license for this particular project [read the LICENSE.md file](LICENSE.md).
For more information about the license for this particular project [read the LICENSE.md file](LICENSE.md).
This project uses [eventemitter3](https://github.com/3rd-Eden/EventEmitter3), is currently MIT licensed and [has it's license information here](https://github.com/3rd-Eden/EventEmitter3/blob/master/LICENSE).

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

var EventEmitter = require('events').EventEmitter;
var _ = require('./utils');

@@ -8,3 +8,3 @@ /**

var action = new EventEmitter(),
var action = new _.EventEmitter(),
eventLabel = "action",

@@ -11,0 +11,0 @@ functor;

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

var EventEmitter = require('events').EventEmitter,
_ = require('./utils');
var _ = require('./utils');

@@ -10,3 +9,3 @@ /**

module.exports = function(definition) {
var store = new EventEmitter(),
var store = new _.EventEmitter(),
eventLabel = "change";

@@ -13,0 +12,0 @@

@@ -1,11 +0,18 @@

var createAction = exports.createAction = require('./createAction');
exports.createAction = require('./createAction');
exports.createStore = require('./createStore');
exports.ListenerMixin = require('./ListenerMixin');
exports.createActions = function(actionNames) {
var i = 0, actions = {};
for (; i < actionNames.length; i++) {
actions[actionNames[i]] = createAction();
actions[actionNames[i]] = exports.createAction();
}
return actions;
};
};
exports.setEventEmitter = function(ctx) {
var _ = require('./utils');
_.EventEmitter = ctx;
};

@@ -26,1 +26,3 @@ /*

};
module.exports.EventEmitter = require('eventemitter3');
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