redux-flux-store
This store enhancer allows objects which resemble stores in traditional Flux to be used in a Redux Reducer. The motivation for this was to allow both the mutations for a property as well as the accessors to be in the same file, as a change in one will likely result in a change in the other. In traditional Flux this was the purpose of a Store, however Redux keeps these two tasks separated into Reducers and Selector.
Installation
npm i redux-flux-store
Usage
Note: The term store
is used to describe an object with a reduce(state, action, waitFor)
method.
state
(Object) - The value of the entry in the global redux state.action
(Object) - The redux action of the form{type: String, ...}
waitFor
(Function) - A function which takes an array of stores and ensures that the values for the specified stores will be updated before continuing execution.
fluxEnhancer(storeMap: Object)
storeMap
: An object which matches a key in the global state to a flux store
which manages that key.
// TeamStore.js; { return Storeteams; } { return Object; } { let update = {}; updateteamDataid = this; return Object; } { } ; // LeaderboardStore.js; { ; let teams = TeamStore; let newTeam = teamsteamId; let leaderboard = _; let index = _ leaderboard; return leaderboard; } { } ; // ReduxStore.js;;; let finalCreateStore = createStore; let store = ; console;// { teams: {}, leaderboard: [], ...reducer() } store;console;// { teams: {H42: {score: 0, id: 'H42'}}, leaderboard: ['H42'], ...reducer(state, action)} ;