Skip to content

sterrahq/microscope-immer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microscope Immer 🔬

Immer.js integration for Microscope.

Table of Contents

Installation

npm install immer @sterra/microscope-immer
# or
yarn add immer @sterra/microscope-immer
# or
pnpm add immer @sterra/microscope-immer

Usage

Before:

import { store } from "@sterra/microscope";

interface Todo {
  text: string;
  done: boolean;
  id: string;
}

const $todos = store<Todo[]>([]);

function addTodo(text: string) {
  const id = crypto.createUUID();
  const newTodo = { id, text, done: false };

  $todos.set((prev) => {
    return [...prev, newTodo];
  });
}

After

import { store } from "@sterra/microscope";
import { withImmer } from "@sterra/microscope-immer";

interface Todo {
  text: string;
  done: boolean;
  id: string;
}

const $todos = store<Todo[]>([]);

function addTodo(text: string) {
  const id = crypto.createUUID();
  const newTodo = { id, text, done: false };

  $todos.set((draft) => {
    draft.push(newTodo);
  });
}