0.1.0 • Published 8 years ago

redux-mori v0.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

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.

0.1.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago