reduced-utils

Tini immutability and reducer utils library

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
reduced-utils
000.1.24 years ago4 years agoMinified + gzip package size for reduced-utils in KB

Readme

reduced-utils
Tini immutability and reducer utils library

Usage

set

import { set } from "reduced-utils";
const myObject = {
    someProp: "value"
};
const value = "Hello World";
const nextObject = set(myObject, ["some", "deep", "value"], value);

console.log(myObject) // {someProp: "value"}
console.log(nextObject) // {someProp: "value", some: {deep: {value: "Hello World"}}}

combineReducers

combineReducers(
  reducers: {
    [sliceName: string]: (
      state: Object, 
      action: Object
    ) => newState: Object
  },
  initialState?: Object
): (state: Object, action: Object) => newState: Object

See: https://redux.js.org/api-reference/combinereducers
const rootReducer = combineReducers({potato: potatoReducer, tomato: tomatoReducer}, {});

createReducer

import { createReducer } from "reduced-utils";
import * as ActionTypes from "../constants/ActionTypes";

const initialState = {
    counter: 0
};

export const counterReducer = createReducer({
  [ActionTypes.INCREASE]: (state, {value = 1}) => ({...state, counter: state.counter + value}),
  [ActionTypes.DECREASE]: (state, {value = 1}) => ({...state, counter: state.counter - value})
}, initialState);