Socket
Book a DemoInstallSign in
Socket

@beardedtim/common-reducers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beardedtim/common-reducers

> Because I got tired of re-writing these every reducer

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Common Reducers

Because I got tired of re-writing these every reducer

Array Methods

Usage

import {add, updateByKey, removeByKey} from '@beardedtim/common-reducers'
const reducer = {
  [ADD_USER]: add,
  [UPDATE_USER]: updateByKey('_id'),
  [REMOVE_USER]: removeByKey('_id')
}

which is dependent on the action looking like this:

addUser(user) // {type: ADD_USER, payload: user}
updateUser({_id: _id, update}) // {type: UPDATE_USER, payload: {_id,update}}
removeUser(_id) // {type: REMOVE_USER, payload: _id}

If you want to remove more than one item at a time, you can use unique=false when creating removeByKey:

[REMOVE_MATCHING_NAME]: removeByKey('name',false)

this will now filter out all objects inside of state who have a property called name that is set to whatever is passed in by removeUser

FAQs

Package last updated on 06 Feb 2017

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