unadlib / mutative

Efficient immutable updates, 2-6x faster than naive handcrafted reducer, and more than 10x faster than Immer.
http://mutative.js.org/
MIT License
1.58k stars 18 forks source link

Proposal: support multiple mark function #15

Closed unadlib closed 10 months ago

unadlib commented 12 months ago

mark option is used to customize either mutable or immutable data. To make it pluggable, we might consider allowing it to support multiple functionalities.

For example,

const immutable = Symbol.for("immutable");

const mutableMark = (target, types) => {
  if (target[immutable]) {
    return types.immutable;
  }
};

const state = create(
  data,
  (draft) => {
    draft.foobar.text = "new text";
  },
  {
    mark: [
      mutableMark,
      (target, { mutable }) => {
        if (target === data.foobar) return mutable;
      }
    ],
  }
);
fantasticsoul commented 11 months ago

Hi friend, through continuous optimization of limu, I recently found that its performance has exceeded mutation. Welcome to communicate with each other ^_^.

git checkout https://github.com/tnfe/limu.git
cd benchmark
npm i
## Then execute the following commands separately
npm run s1
npm run s2
npm run s3
npm run s4