New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

reducer-patterns

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reducer-patterns

A collection of helpers for building reducer functions (usable for Redux, Array().reduce, or any other reducing code)

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

reducer-patterns

reducer-patterns : object

Kind: global namespace

reducer-patterns.async : object

Kind: static namespace of reducer-patterns

async.ConditionalReducer(condition, onTrue, onFalse) ⇒ function

 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

  • condition function - a condition task.
  • onTrue function - reducer to run if true.
  • onFalse function - reducer to run if false.

async.InitState(initializer) ⇒ taskFunction

InitState accepts an initializer function/value, and builds an initial state if none exists

Kind: static method of async
Params

  • initializer function - a condition task.

async.PostprocessState(reducer, postprocessor) ⇒ function

PostprocessState

Kind: static method of async
Params

  • reducer function - the reducer to wrap around.
  • postprocessor function - the postprocessor function to call after the reducer.

async.SeriesReducer(...reducers) ⇒ function

SeriesReducer accepts any number of reducers, and builds a new reducer that chains them together in series

Kind: static method of async
Params

  • ...reducers function - all reducers.

async.SwitchReducer(...reducers) ⇒ function

Kind: static method of async
Params

  • ...reducers function - all reducers.

reducer-patterns.ConditionalReducer(condition, onTrue, onFalse) ⇒ 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

  • condition function - a condition task.
  • onTrue function - reducer to run if true.
  • onFalse function - reducer to run if false.

reducer-patterns.InitState(initializer) ⇒ taskFunction

InitState accepts an initializer function/value, and builds an initial state if none exists

Kind: static method of reducer-patterns
Params

  • initializer function - a condition task.

reducer-patterns.PostprocessState(reducer, postprocessor) ⇒ function

PostprocessState

Kind: static method of reducer-patterns
Params

  • reducer function - the reducer to wrap around.
  • postprocessor function - the postprocessor function to call after the reducer.

reducer-patterns.SeriesReducer(...reducers) ⇒ 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

  • ...reducers function - all reducers.

reducer-patterns.SwitchReducer(...reducers) ⇒ function

Kind: static method of reducer-patterns
Params

  • ...reducers function - all reducers.

Keywords

reducer

FAQs

Package last updated on 31 Jul 2019

Did you know?

Socket

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.

Install

Related posts