
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
reducer-patterns
Advanced tools
A collection of helpers for building reducer functions (usable for Redux, Array().reduce, or any other reducing code)
objectKind: global namespace
object
object
functiontaskFunctionfunctionfunctionfunctionfunctiontaskFunctionfunctionfunctionfunctionobjectKind: static namespace of reducer-patterns
object
functiontaskFunctionfunctionfunctionfunctionfunction let ConditionalReducer = require('reducer-patterns/async/ConditionalReducer');
let state = {
a: 1,
b: 2,
};
let action1 = {
type: 'a',
payload: 2,
};
let action2 = {
type: 'b',
payload: 2,
};
let reducer = ConditionalReducer(
(state, action) => action.type === 'a',
(state, action) => ({
...state,
a: action.payload,
})
);
// prints action1 result { a: 2, b: 2 }
// action1 triggers a state update, since it has the correct type
console.log(
'action1 result',
reducer(state, action1)
);
// prints action2 result { a: 1, b: 2 }
// action2 is ignored, since it has the wrong type
console.log(
'action2 result',
reducer(state, action2)
);
ConditionalReducer
Kind: static method of async
Params
function - a condition task.function - reducer to run if true.function - reducer to run if false.taskFunction
InitState accepts an initializer function/value, and builds an initial state if none exists
Kind: static method of async
Params
function - a condition task.function
PostprocessState
Kind: static method of async
Params
function - the reducer to wrap around.function - the postprocessor function to call after the reducer.function
SeriesReducer accepts any number of reducers, and builds a new reducer that chains them together in series
Kind: static method of async
Params
function - all reducers.function
Kind: static method of async
Params
function - all reducers.function let ConditionalReducer = require('reducer-patterns/ConditionalReducer');
let state = {
a: 1,
b: 2,
};
let action1 = {
type: 'a',
payload: 2,
};
let action2 = {
type: 'b',
payload: 2,
};
let reducer = ConditionalReducer(
(state, action) => action.type === 'a',
(state, action) => ({
...state,
a: action.payload,
})
);
// prints action1 result { a: 2, b: 2 }
// action1 triggers a state update, since it has the correct type
console.log(
'action1 result',
reducer(state, action1)
);
// prints action2 result { a: 1, b: 2 }
// action2 is ignored, since it has the wrong type
console.log(
'action2 result',
reducer(state, action2)
);
ConditionalReducer
Kind: static method of reducer-patterns
Params
function - a condition task.function - reducer to run if true.function - reducer to run if false.taskFunction
InitState accepts an initializer function/value, and builds an initial state if none exists
Kind: static method of reducer-patterns
Params
function - a condition task.function
PostprocessState
Kind: static method of reducer-patterns
Params
function - the reducer to wrap around.function - the postprocessor function to call after the reducer.function
SeriesReducer accepts any number of reducers, and builds a new reducer that chains them together in series
Kind: static method of reducer-patterns
Params
function - all reducers.function
Kind: static method of reducer-patterns
Params
function - all reducers.FAQs
A collection of helpers for building reducer functions (usable for Redux, Array().reduce, or any other reducing code)
The npm package reducer-patterns receives a total of 0 weekly downloads. As such, reducer-patterns popularity was classified as not popular.
We found that reducer-patterns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.