https://github.com/brugarolas/immersible
My own version of Immer. Just for fun!
https://github.com/brugarolas/immersible
copy-on-write immer immutability immutable immutables javascript proxy state-tree
Last synced: 3 months ago
JSON representation
My own version of Immer. Just for fun!
- Host: GitHub
- URL: https://github.com/brugarolas/immersible
- Owner: Brugarolas
- License: gpl-3.0
- Created: 2023-03-26T21:48:46.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-14T16:56:45.000Z (about 2 years ago)
- Last Synced: 2025-02-12T04:09:54.314Z (3 months ago)
- Topics: copy-on-write, immer, immutability, immutable, immutables, javascript, proxy, state-tree
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.buymeacoffee.com/brugarolas)
# 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`:```bash
npm install --save immersible
```And then we import `immersible` where we want to use it.
```js
import { Immersible } from 'immersible'
```## Usage
Usage is quite simple:
```js
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:
```js
console.log(todo.state)
```Differently than with `Immer`, we can set `setAutoFreeze` and `setUseStrictShallowCopy` by object, and not globally:
```js
todo.setAutoFreeze(false)
todo.setAutoFreeze(true)
```We can also subscribe/unsubscribe to changes:
```js
const subscriptionId = todo.subscribe((nextState) =>
console.log(nextState)
);todo.produce((draft) => {
draft[2] = true
})todo.unsubscribe(subscriptionId)
```