Coder Social home page Coder Social logo

ptzagk / redux-map-state Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cyberint/redux-map-state

0.0 0.0 0.0 14 KB

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

License: MIT License

JavaScript 100.00%

redux-map-state's Introduction

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);

redux-map-state's People

Contributors

belkosyak avatar xamfoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.