Comparing version 0.2.8 to 0.2.9
{ | ||
"name": "fluxury", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Add luxury sugar to simplify implementing Facebook's flavor of Flux architecture.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -15,14 +15,24 @@ # fluxury | ||
1. Fluxory.createActions(action1, action2, ..., actionN) | ||
1. Fluxury.dispatch( type, data ) | ||
Submit an action into the stores. You must specify the type and, optionally, some data. | ||
```js | ||
Fluxury.dispatch('REQUEST_SETTINGS') | ||
// or with data | ||
Fluxury.dispatch('LOAD_SETTINGS', { a: 1, b: 2 }) | ||
``` | ||
2. Fluxory.createActions(action1, action2, ..., actionN) | ||
Create your actions from a list of strings as `arguments`. | ||
```js | ||
export default Fluxury.createActions('INC', 'DEC', 'SET') | ||
Fluxury.createActions('INC', 'DEC', 'SET') | ||
``` | ||
This translates to a key mirrored object. | ||
This returns a key mirrored object. | ||
```js | ||
var actions = { | ||
{ | ||
INC: 'INC', | ||
@@ -34,3 +44,3 @@ DEC: 'DEC', | ||
To use your action in a React component: | ||
To use the action in a React component: | ||
@@ -63,3 +73,3 @@ ```js | ||
2. Fluxury.createStore(name, initialState, reducer) | ||
3. Fluxury.createStore(name, initialState, reducer) | ||
@@ -70,3 +80,3 @@ Create a new store with a name and a reducer. | ||
import {INC} from './MyActions' | ||
export default Fluxor.createStore('CountStore', 0, (state, action) => { | ||
export default Fluxor.createStore('CountStore', 0, function(state, action) { | ||
if (action.type === INC) { | ||
@@ -96,3 +106,3 @@ return state + 1; | ||
import {INC} from './MyActions' | ||
export default Fluxury.createStore('CountStore', 0, (state, action) => { | ||
export default Fluxury.createStore('CountStore', 0, function(state, action) { | ||
return state + (action.type === INC ? 1 : 0); | ||
@@ -104,3 +114,2 @@ }) | ||
3. Fluxury.dispatch( type, data ) | ||
@@ -107,0 +116,0 @@ |
12
test.js
@@ -5,3 +5,4 @@ var test = require('tape'); | ||
var Fluxury = require('./lib/index.js') | ||
t.plan(12) | ||
t.plan(13) | ||
t.equal(typeof Fluxury, 'object') | ||
@@ -15,3 +16,3 @@ t.equal(typeof Fluxury.createActions, 'function') | ||
INC = actions.INC, | ||
DEC = actions.DECs, | ||
DEC = actions.DEC, | ||
SET = actions.SET; | ||
@@ -25,5 +26,5 @@ | ||
var store = Fluxury.createStore('MyStore', {}, function(state, action) { | ||
var store = Fluxury.createStore('MapStore', {}, function(state, action) { | ||
var assign = require('object-assign'); | ||
switch (action.type) { | ||
switch (action.type) { | ||
case SET: | ||
@@ -61,3 +62,6 @@ return assign(state, action.data) | ||
Fluxury.dispatch(DEC) | ||
t.equal(store.getState(), 0) | ||
t.deepEqual( Object.keys(store), ['name', 'dispatchToken', 'addListener', 'getState'] ); | ||
}) |
9735
144
138