A helper to use immer as Solid.js Signal to drive state

Overview

Solid Immer

npm version

A helper to use immer as Solid.js Signal to drive state.

Installation

$ npm install solid-immer

Usage

Use createImmerSignal to create a immutable signal. The second value of the tuple is the updater function, which accepts an immer producer function or a value as argument.

{ const todo = draft.find((todo) => todo.id === id); todo.done = !todo.done; }); } function handleAdd() { setTodos((draft) => { draft.push({ id: "todo_" + Math.random(), title: "A new todo", done: false, }); }); } // etc }">
import { createImmerSignal } from "solid-immer";

function App() {
  const [todos, setTodos] = createImmerSignal([
    {
      id: "Solid.js",
      title: "Learn Solid.js",
      done: true,
    },
    {
      id: "Immer",
      title: "Try Immer",
      done: false,
    },
  ]);

  function handleToggle(id) {
    setTodos((draft) => {
      const todo = draft.find((todo) => todo.id === id);
      todo.done = !todo.done;
    });
  }

  function handleAdd() {
    setTodos((draft) => {
      draft.push({
        id: "todo_" + Math.random(),
        title: "A new todo",
        done: false,
      });
    });
  }

  // etc
}

For the full demo see CodeSandbox.

Note

The value of createImmerSignal should not be a primitive.

import { createImmerSignal } from "solid-immer";
import { createSignal } from "solid-js";

createImmerSignal("string"); // TypeError
createSignal("string"); // Good
You might also like...

A JavaScript Library for things I use often, as well as some helper functions

Elements A JavaScript Library for things I use often, as well as some helper functions. Full documentation below. Inspired by Habitat, another library

Apr 21, 2022

A visual helper in vscode to use github's workflow 'hubflow'

vscode-hubflow README This is the README for your extension "vscode-hubflow". After writing up a brief description, we recommend including the followi

Feb 7, 2022

Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

Framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. 🗺️ Remix driver included. 🤟

About routes-gen is a framework agnostic CLI tool for routes parsing and generation of a type-safe helper for safe route usage. Think of it as Prisma,

Jan 2, 2023

Babel plugin and helper functions for interoperation between Node.js native ESM and Babel ESM

babel-plugin-node-cjs-interop and node-cjs-interop: fix the default import interoperability issue in Node.js The problem to solve Consider the followi

Nov 6, 2022

A growing three.js helper library.

A growing three.js helper library.

kokomi.js A growing three.js helper library. Install npm i kokomi.js Hello world With just several lines, you can make a most basic 3D scene :d index.

Dec 30, 2022

A small helper package for discord.js users

A small helper package for discord.js users

helper-djs Helper Djs is a powerful Node.js module Features Error Handler Auto Meme Requirement node v16.14 Installation npm install helper-djs Bot Se

Aug 9, 2022

A set of useful helper methods for writing functions to handle Cloudflare Pub/Sub messages (https://developers.cloudflare.com/pub-sub/)

pubsub A set of useful helper methods for writing functions to handle Cloudflare Pub/Sub messages. This includes: A isValidBrokerRequest helper for au

Dec 4, 2022

Elrond blockchain CLI helper tools - interaction with APIs, smart contracts and protocol

Buildo Begins 👷 Meet Buildo. He is here to help you start creating in the Elrond blockchain ecosystem. Here is where everything begins. I'm going on

Dec 30, 2022

A REST helper for Next.js APIs

REST controller for Next.js How does it work? Create restful controllers in Next.js Example: Inside /pages/api/auth/[...handler] (filename must be a r

Jul 30, 2022
Owner
Shuaiqi Wang
洋码子工作者
Shuaiqi Wang
A SolidJS starter template with solid-labels, solid-sfc and solid-styled

solid-sfc-styled-labels-starter This is a SolidJS starter template for easily setting up solid-sfc, solid-styled and solid-labels. Development Install

Alexis H. Munsayac 9 Mar 25, 2022
This is a simple script to upload Multiple files into google drive using google drive API and Nodejs.

Welcome to gDrive Multiple File Upload ?? This is a simple script to upload Multiple files into google drive using google drive API and Nodejs Install

Jayamal Sanuka Hettiarachchi 1 Dec 29, 2021
Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir Lab e na Loritta Helper do serivdor de suporte da Loritta.

Ticket Bot Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir

ADG 6 Dec 21, 2022
📦 Fully typed and immutable store made on top of Immer with mutation, action, subscription and validation!

Riux is a fully typed and immutable store made on top of Immer with mutation, action, subscription and validation! Table of contents ?? Installation U

null 10 Aug 27, 2022
A SolidJS signal tracking dependency & structural visualizer developer tool

Solid JS DevTool Developer tool that visualizes Solid's signal architecture, including the components. It can be added to any Solid JS application. In

OSLabs Beta 58 Nov 5, 2022
Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Maciej Kwaśniak 55 Dec 30, 2022
Index your Google Drive Easily and Free.

Google Personal/Shared Drive Index Full White label and Customizable Index | One of a kind Supports Both My and Team/Shared Drives with Dark Mode. Cli

Moto One Fusion + 26 Sep 22, 2021
Todas as aulas da Semana JS Expert 5.0 - Google Drive Clone

Google Drive Clone - Semana JS Expert 5.0 Seja bem vindo(a) à quinta Semana Javascript Expert. Este é o código inicial para iniciar nossa jornada. Mar

Erick Wendel 1.5k Dec 29, 2022
This extension injects a button to the Google Drive WebUI.

This extension injects a button to the Google Drive WebUI. When clicking on it the current folder id is send to your gogdl-ng instance. It was developed and tested on the latest version of Mozilla Firefox and Chrome.

null 5 Jul 13, 2022
🔻 Generate a Google Drive direct download link based on the URL or ID

Drive Link Generate a Google Drive direct download link based on the URL or ID. Usage The API is the same on all this platforms ✔️ Deno ?? import { dr

Eliaz Bobadilla 10 Nov 1, 2022