New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

immersible

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immersible

My own version of Immer with a more convenient API

1.1.0
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

"Buy Me A Coffee"

Immersible

Immersible is my own version of Immer. It is more restrictive and has, in my opinion, a more convenient API. You can also subscribe to changes with my library.

Installation

First, we need to install immersible:

npm install --save immersible

And then we import immersible where we want to use it.

import { Immersible } from 'immersible'

Usage

Usage is quite simple:

const todo = new Immersible([
    {
        title: "Learn TypeScript",
        done: true
    },
    {
        title: "Try Immer",
        done: false
    }
]);

todo.produce((draft) => {
  draft[1] = true
  draft.push({ title: "Tweet about it", done: false })
})

We can access baseState or, if mutated, nextState way simple:

console.log(todo.state)

Differently than with Immer, we can set setAutoFreeze and setUseStrictShallowCopy by object, and not globally:

todo.setAutoFreeze(false)
todo.setAutoFreeze(true)

We can also subscribe/unsubscribe to changes:

const subscriptionId = todo.subscribe((nextState) =>
  console.log(nextState)
);

todo.produce((draft) => {
  draft[2] = true
})

todo.unsubscribe(subscriptionId)

Keywords

javascript

FAQs

Package last updated on 28 Mar 2023

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