Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ikhsaan/create-reducer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ikhsaan/create-reducer

Creating reducer with object properties more object oriented by definition than traditional switch-case procedural without any dependencies

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Create Reducer

Behind

Read this ebook Programming Javascript Applications and find 'Don't Use switch'

Installation

npm i -S @ikhsaan/create-reducer

// or

yarn add @ikhsaan/create-reducer

Usage

NOTE: Assume you use seamless-immutable / immutable-js. otherwise use spread object instead


import createReducer from '@ikhsaan/create-reducer'

createReducer(INITIAL_STATE, {
 [FAILURE](state, { error }) {
   return state.set('error', error);
 },
 [INCREMENT](state) {
   return state.update('count', increment);
 },
 [LOAD_DATA_SUCCESS](state, action) {
   return state.merge({ placeholderData: action.data });
 },
 [TICK_CLOCK](state, action) {
   return state.set('lastUpdate', action.ts).set('light', !!action.light);
 },
});

// or

const failure = (state, { error }) => state.set('error', error);

const updateTick = (state, action) => state.set('lastUpdate', action.ts).set('light', !!action.light);

createReducer(INITIAL_STATE, {
 [FAILURE]: failure,
 [TICK_CLOCK]: updateTick
});

Keywords

FAQs

Package last updated on 26 Feb 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc