Skip to content

chulanovskyi/redux-compose-reducer

 
 

Repository files navigation

Redux Compose Reducer build status npm version npm downloads license tested with jest

Reducer's composer for Redux. This library simplifies workflow for building namespaced actions and reducers for them in Redux.

Installation

Install from the NPM repository using yarn or npm:

yarn add redux-compose-reducer
npm install --save redux-compose-reducer

Usage

To create namespaced types for your actions you can use function createTypes in this way:

import { createTypes } from 'redux-compose-reducer'

export const TYPES = createTypes('app', ['openSideBar', 'closeSideBar'])

export const openSideBar = () => ({
  type: TYPES.openSideBar,
})

export const closeSideBar = () => ({
  type: TYPES.closeSideBar,
})

After it you need to create reducers for this types, right? Try this:

import { composeReducer } from 'redux-compose-reducer'
import { TYPES } from './actions'

const openSideBar = state => ({
  ...state,
  open: true,
})

// if your reducer doesn't require state and action
// you can declare it as object that describes changes
const closeSideBar = { open: false }

export default composeReducer({
  types: TYPES,
  initialState: { open: false },
  reducers: {
    openSideBar,
    closeSideBar,
  },
})

About

Reducer's composer for Redux

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%