Giter Club home page Giter Club logo

ionic-bond's Introduction

ionic-bond

English | 简体中文


Auto Test CI Publish CI npm version

A library for updating immutable states in JavaScript applications.

Introduction

This library is a very lightweight replacement for immer, the core implementation also uses the magic of Proxy, but the exported API only has a solvent function.

In other words, if you are worried about cumbersome code like below, you can try ionic-bond without having to include a huge immer.

setState((prev) => ({
  ...prev,
  userStore: {
    ...prev.userStore,
    currentUser: {
      ...prev.userStore.currentUser,
      userName: "some updated user name",
    },
  },
}));

With ionic-bond, your code will look like this:

import { solvent } from "ionic-bond";

setState(
  (prev) =>
    solvent() // If you are using `TypeScript`, you can use `solvent<YourType>()` to get type inference for the `obj` parameter.
      .ionize((obj) => obj.userStore.currentUser.userName)
      .dissolve(prev)
      .crystallize("some updated user name") // will return a new object with replaced `userName`
);

The reason for these API names is updating object in this form is much like dissolving some crystals in a solvent, then replacing some of the ions in the solution and recrystallizing.

Although these APIs can be designed as a function that accepts three parameters, in order to facilitate the reuse of property selectors and objects before updating, they are hierarchical, that is, curried at the API level.

License

 __________________
< The MIT license! >
 ------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ionic-bond's People

Contributors

darrendanielday avatar

Stargazers

QUALIA avatar Roman avatar BaoLei avatar 厄月 avatar 友人A avatar  avatar ben upsilon avatar  avatar shank avatar buhi avatar 小付同学 avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.