Socket
Socket
Sign inDemoInstall

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.0 to 0.1.1

2

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

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

@@ -376,3 +376,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){

return function() {
action.removeListener(eventLabel, eventHandler);
store.removeListener(eventLabel, eventHandler);
};

@@ -389,5 +389,13 @@ };

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

@@ -419,4 +427,5 @@ /*

};
},{}]},{},[4])
(4)
});

@@ -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(){action.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){c.createAction=a("./createAction"),c.createStore=a("./createStore")},{"./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){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)});
{
"name": "reflux",
"version": "0.1.0",
"version": "0.1.1",
"description": "A simple library for uni-directional dataflow application architecture inspired by ReactJS Flux",

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

@@ -22,6 +22,7 @@ # Reflux

* Instead of a singleton dispatcher, every action is a dispatcher by themselves
* No more type checking with strings, just let the stores listen to actions and don't worry!
* Data stores are also dispatchers and stores may listen for changes on other stores
* Instead of a singleton dispatcher, every action handles the dispatching by themselves
* Javascript is a dynamic language so no more static type checking with strings! Just let the stores listen to actions and don't worry!
You can read more in this [blog post about React Flux vs Reflux](http://spoike.ghost.io/deconstructing-reactjss-flux/).
## Installation

@@ -55,4 +56,24 @@

It is as simple as that.
An action is a functor that can be invoked like any function.
```javascript
statusUpdate(); // Invokes the action statusUpdate
```
It is as simple as that. There is also a convenience function for creating multiple actions.
```javascript
var Actions = Reflux.createActions([
"statusUpdate",
"statusEdited",
"statusAdded"
]);
// Actions object now contains the actions
// with the names given in the array above
// that may be invoked as usual
Actions.statusUpdate();
```
### Creating data stores

@@ -59,0 +80,0 @@

@@ -32,3 +32,3 @@ var EventEmitter = require('events').EventEmitter,

return function() {
action.removeListener(eventLabel, eventHandler);
store.removeListener(eventLabel, eventHandler);
};

@@ -35,0 +35,0 @@ };

@@ -1,3 +0,11 @@

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

@@ -25,2 +25,2 @@ /*

return typeof value === 'function';
};
};

@@ -32,14 +32,50 @@ var chai = require('chai'),

describe('and when calling the action with arbitrary params', function() {
it('should receive the correct arguments', function() {
var testArgs = [1337, 'test'];
action(testArgs[0], testArgs[1]);
beforeEach(function() {
action(testArgs[0], testArgs[1]);
});
return assert.eventually.deepEqual(promise, testArgs);
});
it('should receive the correct arguments', function() {
return assert.eventually.deepEqual(promise, testArgs);
});
});
describe('Creating multiple actions to an action definition object', function() {
var actionNames, actions;
beforeEach(function () {
actionNames = ['foo', 'bar'];
actions = Reflux.createActions(actionNames);
});
it('should contain foo and bar properties', function() {
assert.property(actions, 'foo');
assert.property(actions, 'bar');
});
it('should contain action functor on foo and bar properties', function() {
assert.isFunction(actions.foo);
assert.isFunction(actions.bar);
});
describe('when listening to any of the actions created this way', function() {
var promise;
beforeEach(function() {
promise = Q.promise(function(resolve) {
actions.foo.listen(function() {
resolve(Array.prototype.slice.call(arguments, 0));
});
});
});
it('should receive the correct arguments', function() {
var testArgs = [1337, 'test'];
actions.foo(testArgs[0], testArgs[1]);
return assert.eventually.deepEqual(promise, testArgs);
});

@@ -46,0 +82,0 @@

@@ -24,3 +24,5 @@ var chai = require('chai'),

actionCalled: function() {
resolve(Array.prototype.slice.call(arguments, 0));
var args = Array.prototype.slice.call(arguments, 0);
this.trigger(args);
resolve(args);
}

@@ -56,8 +58,42 @@ });

setTimeout(done, 200);
setTimeout(done, 20);
});
});
describe('listening to the store', function() {
var unsubStoreCallback, storeListenPromise;
beforeEach(function() {
storeListenPromise = Q.promise(function(resolve) {
unsubStoreCallback = store.listen(function() {
resolve(Array.prototype.slice.call(arguments, 0));
});
});
});
it('should pass when triggered', function() {
action(1337, 'ninja');
assert.eventually.deepEqual(storeListenPromise, [1337, 'ninja']);
});
describe('and unsubscribed', function() {
beforeEach(function () {
unsubStoreCallback();
});
it('shouldn\'t have been called when action is called', function(done) {
action(1337, 'ninja');
promise.then(function() {
assert.fail();
});
setTimeout(done, 20);
});
});
});
});
});
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