Comparing version 1.1.0 to 1.2.0
@@ -10,3 +10,2 @@ /* fluxury - Copyright 2015 Peter Moresi */ | ||
exports.dispatch = dispatch; | ||
exports.createStore = createStore; | ||
@@ -74,3 +73,3 @@ var EventEmitter = require('events').EventEmitter; | ||
function dispatch(type, data) { | ||
function _dispatch(type, data) { | ||
if (typeof type === 'string') { | ||
@@ -85,2 +84,3 @@ dispatcher.dispatch({ type: type, data: data }); | ||
exports.dispatch = _dispatch; | ||
function createStore(name, initialState, reducer) { | ||
@@ -149,3 +149,3 @@ var methods = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
}), | ||
addListener: function addListener(cb) { | ||
subscribe: function subscribe(cb) { | ||
if (typeof cb !== 'function') { | ||
@@ -166,6 +166,15 @@ throw "Callback must be a function"; | ||
}, | ||
replaceState: process.env.NODE_ENV === 'development' ? function () { | ||
replaceState: process.env.NODE_ENV === 'development' ? function (state) { | ||
currentState = state; | ||
} : undefined, | ||
replaceReducer: process.env.NODE_ENV === 'development' ? function (reducer) { | ||
reduce = reducer; | ||
} : undefined, | ||
dispatch: function dispatch() { | ||
for (var _len2 = arguments.length, action = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
action[_key2] = arguments[_key2]; | ||
} | ||
return _dispatch(action); | ||
}, | ||
getState: function getState(cb) { | ||
@@ -172,0 +181,0 @@ return currentState; |
{ | ||
"name": "fluxury", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Add luxury sugar to simplify implementing Facebook's flavor of Flux architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -89,6 +89,8 @@ # fluxury | ||
| name | The name supplied when creating the store | | ||
| dispatch | Another method to access the dispatch function | | ||
| dispatchToken | A number used with waitFor | | ||
| addListener | A function to add a callback for events | | ||
| subscribe | A function to register listeners | | ||
| getState | A function that returns the current state | | ||
| replaceState | Replace the state; development only | | ||
| replaceReducer | Replace the reducer; development only | | ||
@@ -95,0 +97,0 @@ ## Put it all together |
@@ -137,3 +137,3 @@ /* fluxury - Copyright 2015 Peter Moresi */ | ||
}), | ||
addListener: function(cb) { | ||
subscribe: function(cb) { | ||
if (typeof cb !== 'function') { | ||
@@ -154,5 +154,7 @@ throw "Callback must be a function"; | ||
}, | ||
replaceState: ((process.env.NODE_ENV === 'development') ? () => { | ||
currentState = state }: undefined) | ||
, | ||
replaceState: ((process.env.NODE_ENV === 'development') ? (state) => { | ||
currentState = state }: undefined), | ||
replaceReducer: ((process.env.NODE_ENV === 'development') ? (reducer) => { | ||
reduce = reducer }: undefined), | ||
dispatch: (...action) => dispatch(action), | ||
getState: function(cb) { | ||
@@ -159,0 +161,0 @@ return currentState; |
10
test.js
@@ -36,3 +36,3 @@ var test = require('tape'); | ||
var listenerCount = 0; | ||
store.addListener( () => listenerCount++ ) | ||
store.subscribe( () => listenerCount++ ) | ||
fluxury.dispatch(SET, { foo: 1, bar: 2 }) | ||
@@ -76,3 +76,3 @@ t.deepEqual(store.getState(), { foo: 1, bar: 2 }) | ||
t.deepEqual( Object.keys(store).sort(), ['name', 'dispatchToken', 'addListener', 'replaceState', 'getState'].sort() ); | ||
t.deepEqual( Object.keys(store).sort(), [ 'dispatch', 'dispatchToken', 'getState', 'name', 'replaceReducer', 'replaceState', 'subscribe' ].sort() ); | ||
}) | ||
@@ -138,4 +138,6 @@ | ||
'dispatchToken', | ||
'addListener', | ||
'subscribe', | ||
'replaceState', | ||
'replaceReducer', | ||
'dispatch', | ||
'getState' | ||
@@ -190,3 +192,3 @@ ]); | ||
var token = MessageStore.addListener(function() { | ||
var token = MessageStore.subscribe(function() { | ||
dispatchCount += 1 | ||
@@ -193,0 +195,0 @@ }) |
52346
1106
196
9