Comparing version 0.1.1 to 0.2.2
78
index.js
@@ -6,43 +6,45 @@ import {EventEmitter} from 'fbemitter'; | ||
export default function Fluxury(config) { | ||
return Object.freeze({ | ||
/* thin bridge to internal dispatcher */ | ||
dispatch: function(action) { | ||
dispatcher.dispatch(action) | ||
}, | ||
/* transform a list of actions into useful functions */ | ||
createActions: function(actions) { | ||
return actions.reduce(function(a,b) { | ||
return a[b] = function(data) { | ||
return dispatcher.dispatch({ type: b, data: data })), {}); | ||
} | ||
export default Object.freeze({ | ||
/* thin bridge to internal dispatcher */ | ||
dispatch: function(action) { | ||
dispatcher.dispatch(action) | ||
}, | ||
/* transform a list of actions into useful functions */ | ||
createActions: function(actions) { | ||
return actions.reduce(function(a,b) { | ||
a[b] = b; | ||
return a; | ||
}, {}); | ||
}, | ||
/* create a named store with an initialState and a reducer to move it forward */ | ||
createStore: function(name, initialState, reducer, waitFor=[]) { | ||
var currentState = initialState; | ||
var emitter = new EventEmitter(); | ||
var subscription; | ||
var dispatchToken = dispatcher.register( function(action) { | ||
dispatcher.waitFor(waitFor); | ||
var newState = reducer(currentState, action); | ||
if (currentState !== newState) { | ||
currentState = newState; | ||
emitter.emit(changedEvent); | ||
} | ||
}, | ||
/* create a named store with an initialState and a reducer to move it forward */ | ||
createStore: function(name, initialState, reducer, waitFor=[]) { | ||
var currentState = {}; | ||
var emitter = new EventEmitter(); | ||
var subscription; | ||
}); | ||
var dispatchToken = dispatcher.register( function(action) { | ||
dispatcher.waitFor(waitFor); | ||
var newState = reducer(currentState, action); | ||
if (currentState !== newState) { | ||
emitter.emit(changedEvent); | ||
} | ||
}); | ||
return Object.freeze({ | ||
name: name, | ||
dispatchToken: dispatchToken, | ||
addListener: function(cb) { | ||
return emitter.addListener(changedEvent, cb) | ||
}, | ||
getState: function(cb) { | ||
return currentState; | ||
} | ||
}); | ||
return Object.freeze({ | ||
name: name, | ||
dispatchToken: dispatchToken, | ||
addListener: function(cb) { | ||
return emitter.addListener(changedEvent, cb) | ||
}, | ||
getState: function(cb) { | ||
return currentState; | ||
} | ||
}); | ||
} | ||
} | ||
}) | ||
} | ||
}); |
{ | ||
"name": "fluxury", | ||
"version": "0.1.1", | ||
"version": "0.2.2", | ||
"description": "Add luxury sugar to simplify implementing Facebook's flavor of Flux architecture.", | ||
"main": "index.js", | ||
"main": "./lib/index.js", | ||
"jsnext:main": "index.js", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "node test" |
@@ -7,4 +7,6 @@ # fluxury | ||
This library is an opinionated set of functions that allow you to create actions, stores and web utils. | ||
This library is an opinionated set of functions that allow you to easily actions and stores; and a pattern on how to submit these actions to the dispatcher. | ||
This new "Flux framework" is a sparse 3 functions and 46 lines of commented ES6 code. Enjoy! | ||
## API | ||
@@ -36,2 +38,3 @@ | ||
var React = require('react'); | ||
var Fluxury = require('fluxury'); | ||
var PropTypes = React.PropTypes; | ||
@@ -42,3 +45,4 @@ | ||
handleClick: function() { | ||
INC() | ||
/* Call dispatch to submit the action to the stores */ | ||
Fluxury.dispatch(INC) | ||
} | ||
@@ -141,5 +145,1 @@ | ||
``` | ||
That's it. This new Flux framework is a sparse 3 functions and 46 lines of commented code. | ||
Enjoy! |
7802
6
88