Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 2.04 KB

README.md

File metadata and controls

47 lines (33 loc) · 2.04 KB

Warped Reducers

Build Status Greenkeeper Enabled

Compile a standard Redux reducer from a brief definition.

Usage in Node depends on --experimental-modules. With older Node versions, use esm.

API

This is also the default export from this module.

Given a String representing the namespace, and a StrMap of action handlers, returns a Record containing a single reducer, and a new StrMap mapping the original keys to canonical identifiers of the types that the reducer can handle.

An action handler is a curried function that takes the payload of the action first, and the state second, and should return a new state. We recommend usings Optics, such as the lens-related functions from Ramda, to define the reducers - the signature of action handlers is designed to align perfectly with the signature of functional utilities.

const setMyProp = myProp => state => Object.assign ({}, state, {myProp});
createReducer ('MyNamespace') ({setMyProp});

A conviently named function that does nothing to your state.

To be used when you need to define an action type which should not affect the state, but can be used as a message to your Redux side-effect handling middleware.

> noopAction ({do: 'nothing'}) ({myState: 'whatever'})
{myState: 'whatever'}