3.12.4 • Published 3 months ago

limu v3.12.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

limu 🍋

limu is short for love immutable, born for efficient creation and operation of immutable object, based on shallow copy on read and mark modified on write mechanism.

It is fast, It is nearly more than 2 or 20 times faster than immer in different situations. Click this online perf demo to review the amazing result.

No freeze by default, limu is 10 times or more faster than Immer in most scenarios

  • Debugging friendly, view draft directly anytime without current.
  • Smaller package, only 4.3kb gzip.
  • No freeze by default, faster than immer in different situations.
  • Natural Support for map and Set.

Pay attention, limu can only run on JavaScript runtime that supports proxy

Performance ⚡️

No freeze by default, limu is 10 times or more faster than Immer in most scenarios after 3.7 version, limu is now the fastest immutable js lib of all ( faster than immer and mutative ).

test 1 (inspired by this immer case ) npm.io

test 2 test 2

The performance testing process is as follows

git clone https://github.com/tnfe/limu
cd limu
npm i
cd benchmark
npm i
node opBigData.js // trigger test execution, the console echoes the result
# or
node caseOnlyRead.js
npm run s1
npm run s2
npm run s3
npm run s4

You are very welcome to submit your test to the benchmark directory or test directory

Quick Start

install

npm i limu

apis

import { produce, createDraft, finishDraft } from 'limu';

produce

const baseState = {
  a: 1,
  b: [1, 2, 3],
  c: {
    c1: { n: 1 },
    c2: { m: 2 },
  },
};
const nextState = produce(baseState, (draft) => {
  draft.a = 2;
  draft.b['2'] = 100;
});

console.log(nextState === baseState); // false
console.log(nextState.a === baseState.a); // false
console.log(nextState.b === baseState.b); // false
console.log(nextState.c === baseState.c); // true

Currying call

const producer = produce((draft) => {
  draft.a = 2;
  draft.b['2'] = 100;
});
const nextState = producer(baseState);

createDraft, finishDraft

const draft = createDraft(baseState);
draft.a = 2;
draft.b = [];
const nextState = finishDraft(draft);

console.log(nextState === baseState); // false
console.log(nextState.a === baseState.a); // false
console.log(nextState.b === baseState.b); // false
console.log(nextState.c === baseState.c); // true

Experience limu on the console

logo

As limu is an immutable js library based on shallow copy on read and mark modified on write. Based on this mechanism, so it is more friendly to debugging. You can copy the following code to the console experience

there are 2 ways to quickly experience limu and compare limu with immer.

  • 1, open limu doc site and right-click to open the console.

  • 2, visit unpkg, right-click to open the console, and then paste the following code to load js

function loadJs(url) {
  const dom = document.createElement('script');
  dom.src = url;
  document.body.appendChild(dom);
}

loadJs('https://unpkg.com/limu@3.5.5/dist/limu.min.js'); // load limu umd bundle
loadJs('https://unpkg.com/immer@9.0.21/dist/immer.umd.production.min.js'); // load immer umd bundle

Then you can paste below codes to run

  • case 1
function oneCase(produce) {
  const demo = { info: Array.from(Array(10000).keys()) };
  produce(demo, (draft) => {
    draft.info[2000] = 0;
  });
}

function runBenchmark(produce, label) {
  const start = Date.now();
  const limit = 100;
  for (let i = 0; i < limit; i++) {
    oneCase(produce);
  }
  console.log(`${label} avg spend ${(Date.now() - start) / limit} ms`);
}

function run() {
  immer.setAutoFreeze(false);
  runBenchmark(immer.produce, 'immer,');
  runBenchmark(limu.produce, 'limu,');
}
  • case 2
lib = window.limu; // or lib = window.immer
const base = {
  a: 1,
  b: { b1: 1, b2: 2, b3: { b31: 1 } },
  c: [1, 2, 3],
  d: { d1: 1000 },
};
const draft = lib.createDraft(base);
draft.a = 200;
draft.b.b1 = 100;
console.log(draft);
draft.c.push(4);
const final = lib.finishDraft(draft);
console.log(base === final); // false
console.log(base.a === final.a); // false
console.log(base.b === final.b); // false
console.log(base.b.b3 === final.b.b3); // true
console.log(base.c === final.c); // false
console.log(base.d === final.d); //true

Higher observability will greatly improve the development and debugging experience, as shown in the figure below, after unfolding the limu draft, you can observe all data nodes of the draft in real time

And the immer or mutative expansion is like this

License

Copyright (c) Tencent Corporation. All rights reserved.

Limu is released under the MIT License(https://opensource.org/licenses/MIT)

3.12.4

3 months ago

3.12.3

4 months ago

3.12.2

4 months ago

3.12.1

4 months ago

3.12.0

4 months ago

3.11.8

5 months ago

3.11.7

5 months ago

3.11.9

5 months ago

3.11.10

5 months ago

3.11.6

5 months ago

3.11.5

5 months ago

3.11.4

5 months ago

3.11.3

5 months ago

3.9.2

5 months ago

3.9.1

5 months ago

3.9.0

5 months ago

3.10.1

5 months ago

3.10.0

5 months ago

3.10.2

5 months ago

3.8.4

6 months ago

3.11.0

5 months ago

3.11.2

5 months ago

3.11.1

5 months ago

3.5.7

8 months ago

3.7.3

7 months ago

3.7.2

7 months ago

3.5.8

8 months ago

3.8.0

6 months ago

3.6.0

8 months ago

3.8.3

6 months ago

3.8.2

6 months ago

3.8.1

6 months ago

3.7.1

7 months ago

3.7.0

7 months ago

3.3.9

10 months ago

3.5.6

9 months ago

3.3.8

10 months ago

3.5.5

9 months ago

3.3.7

10 months ago

3.5.4

9 months ago

3.3.6

10 months ago

3.4.0

10 months ago

3.2.2

10 months ago

3.2.1

10 months ago

3.4.3

10 months ago

3.4.2

10 months ago

3.4.1

10 months ago

3.3.1

10 months ago

3.3.0

10 months ago

3.5.3

9 months ago

3.3.5

10 months ago

3.5.2

9 months ago

3.3.4

10 months ago

3.5.1

9 months ago

3.3.3

10 months ago

3.5.0

10 months ago

3.3.2

10 months ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.0.2

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

3.1.2

2 years ago

3.2.0

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago