You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

immutable-state-creator

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-state-creator

utilities to create immutable state

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

Create Immutable State Easily travis-ci

An utility to easily create immutable state for Redux

Usage

Primitive types

  • Define the State
import { createState, StateObject } from 'immutable-state-creator'

const State = createState('User', {
  name: 'my name',
  age: 10,
  languages: ['English'],
  pets: List.of('cat'),
  active: true,
})
  • Create initial state
const initState = State.create()
  • Use getter to select value
expect(State.get('age')(initState)).toBe(10)
expect(State.get('name')(initState)).toBe('my name')
  • Use setter to update a value
const newState = State.set('age', 20)(initState)
expect(State.get('age')(newState)).toBe(20)

Toggle boolean value

const initState = State.create()
expect(initState.active).toBe(true)
const newState = State.toggle('active')(initState)
expect(newState.active).toBe(false)

Keywords

typescript

FAQs

Package last updated on 08 Mar 2020

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