redux-transduce
npm install --save redux-transducetransduce(xform, reducer)
transduce(xform, reducer)Caveat: not all transducers are supported
Simple example: filtering action types
import { filter } from 'transducers.js';
import transduce from 'redux-transduce';
const addTodoReducer = transduce(
filter(action => action.type === 'ADD_TODO'),
(state, action) => ({ ...state, todos: [...state.todos, action.payload })
);
const removeTodoReducer = transduce(
filter(action => action.type === 'ADD_TODO'),
(state, action) => ({ ...state, todos: todos.filter(t => t.id !== action.payload.id) })
);
// Combine into a single reducer with reduce-reducers
// https://github.com/acdlite/reduce-reducers
import reduceReducers from 'reduce-reducers';
const todoReducer = reduceReducers(addTodoReducer, removeTodoReducer);Last updated