0.2.1 • Published 8 years ago

redux-map-state v0.2.1

Weekly downloads
13
License
MIT
Repository
github
Last release
8 years ago

redux-map-state

Higher-order Redux reducer which helps apply your existent reducers on any format of state

Usage

Install via NPM

npm install redux-map-state --save

Import

import mapState from 'redux-map-state'; 
// or
var mapState = require('redux-map-state');

If you need ES6 module

import mapState from 'redux-map-state/es6';

Use this if you are using rollup.js or webpack 2, or any ES2015 modules-compatible bundler which can eliminate unused library code with tree-shaking.

It is recommended to import the library from redux-map-state/es6 instead of redux-map-state/src because the source code depends on experimental presets from babel (stage 1-3) and may be incompatible with your bundler or settings.

Other environments

Use the Universal Module Definition (UMD)

API

mapState()

mapState(
  options: {
    before: ?(stateBefore: any) => newStateBefore,
    after: ?(stateAfter: any) => newStateAfter,
    actionTypes: ?Array<string>
  }
): (reducer) => reducer

Creates a higher-order reducer which maps state before and after passing to a reducer, but does it only for passed action types.

Useful when you want reuse your reducer on state, which has another format.

Example

Lets say we have reducer which handles list of objects, but we want to use it on subtree, which is only one object.

import listReducer from 'listReducer';

const objectReducer = mapState({
  before: (obj) => [obj],
  after: (list) => list[0]
})(listReducer);
0.2.1

8 years ago

0.2.0

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago