redux-convention
v1.0.1
Published
Facilitates conversion of Flux Standard Action (FSA) to Canonical Composition Action (CCA) and vice-versa.
Downloads
6
Readme
redux-convention
Facilitates conversion of Flux Standard Action (FSA) to Canonical Composition Action (CCA) and vice-versa.
Usage
Function
redux-convention
exposes mapper
object that in turn defines two functions: fromCCAtoFSA
and fromFSAtoCCA
. Input is a plan object. Output is a shallow copy of the input with mapped properties.
import {
mapper
} from 'redux-convention';
let CCAction,
FSAction;
CCAction = {
name: 'foo',
data: {
foo: 'bar'
},
metadata: {
baz: 'qux'
}
};
FSAction = mapper.fromCCAtoFSA(CCAction);
CCAction = mapper.fromFSAtoCCA(FSAction);
Middleware
redux-convention
exposes middleware
object that in turn defines two functions: fromCCAtoFSA
and fromFSAtoCCA
. These functions are designed to work with Redux middleware, specifically, the applyMiddleware
function.
Middleware can be used multiple times to convert FSA to CCA.
import {
createStore,
applyMiddleware
} from 'redux';
import {
middleware as convention
} from 'redux-convention';
import {
combineReducers
} from 'redux-immutable';
import * as reducers from './reducers';
import Immutable from 'immutable';
let reducer,
state,
store;
reducer = combineReducers(reducers);
state = Immutable.Map({});
state = reducer(state, {
name: `CONSTRUCT`
});
store = applyMiddleware(
// Middleware that uses CCA.
convention.fromCCAtoFSA,
// Middleware that uses FSA.
convention.fromFSAtoCCA,
// Middleware that uses CCA.
)(createStore)(reducer, state);
export default store;