Skip to content

redbadger/redux-mori

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-mori

NPM version

redux-mori is a drop-in replacement for Redux's combineReducers and createStore that works with mori.js immutable data structures.

Any preloadedState for Redux's createStore should be a mori hashMap.

Usage

If you create a store with preloadedState, make sure it is an instance of hashMap:

Create Store / Combine Reducers:

import { toClj } from 'mori';
import { combineReducers, createStore } from 'redux-mori';
import fooReducer from './fooReducer';
import bazReducer from './bazReducer';

const preloadedState = toClj({foo: 'bar', baz: 'quux'});
const rootReducer = combineReducers({fooReducer, bazReducer});
const store = createStore(rootReducer, preloadedState);

Action:

const ACTION_REQUEST = 'ACTION_REQUEST'
const actionRequest = () => hashMap('type', ACTION_REQUEST)

Please note you can still use original redux createStore and write actions as JS objects, even if you're using mori in your state.

Logger

If you're using Redux Logger and would like to get readable logs of state and actions, you can use our createLogger wrapper. You can use it exactly in the same way as the original but it presets following values:

{
  actionTransformer,
  collapsed: true,
  stateTransformer,
}

Example:

import createLogger from 'redux-mori/dist/createLogger';
import { createStore } from 'redux-mori';
import { applyMiddleware } from 'redux';
const middlewares = [];
if (isDev) {
  const logger = createLogger({
    predicate: (getState, action) => !/EFFECT_/.test(action.type),
  });
  middlewares.push(logger);
}

const store = createStore(rootReducer, applyMiddleware(...middlewares));

Actions get transformed fully into JS if they are mori objects. If they are JS objects with only some values as mori structures, it will transform this data into JS as well.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors