-
-
Notifications
You must be signed in to change notification settings - Fork 854
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from immerjs/multi-bundle
feat: Immer has been made tree-shakeable, and minimal size has been halved, from 6.1 to 3.1 KB gzipped BREAKING CHANGE: Support for ES5, patches and Map/Set collections has to be _explicitly_ enable now: https://immerjs.github.io/immer/docs/installation BREAKING CHANGE: Custom serialization hooks are no longer supported feat: Adding large data sets to a draft has been optimized (in case autofreeze is disabled)
- Loading branch information
Showing
80 changed files
with
8,254 additions
and
5,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["modern-browsers"] | ||
"presets": [["@babel/preset-env", { "targets": { "ie": "11" } }]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,5 +58,6 @@ typings/ | |
.env | ||
|
||
.idea | ||
dist/ | ||
/dist/ | ||
website/build | ||
.rts2* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
// Note; this config requires node 8.4 or higher | ||
"type": "node", | ||
"protocol": "auto", | ||
"request": "launch", | ||
"name": "debug unit test", | ||
"stopOnEntry": false, | ||
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js", | ||
"args": ["--verbose", "--testRegex",".*", "-i", "${file}"], | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
] | ||
} | ||
] | ||
} | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
// Note; this config requires node 8.4 or higher | ||
"type": "node", | ||
"protocol": "auto", | ||
"request": "launch", | ||
"name": "debug unit test", | ||
"stopOnEntry": false, | ||
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js", | ||
"args": ["--verbose", "-i", "${file}"], | ||
"runtimeArgs": ["--nolazy"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
{} | ||
{ | ||
"ignore_dirs": ["node_modules", "_site", "dist", "coverage"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,115 @@ | ||
"use strict" | ||
|
||
import {measure} from "./measure" | ||
import produce, {setAutoFreeze, setUseProxies} from "../dist/immer.umd.js" | ||
import produce, { | ||
setAutoFreeze, | ||
setUseProxies, | ||
enableAllPlugins | ||
} from "../dist/immer.cjs.production.min.js" | ||
import cloneDeep from "lodash.clonedeep" | ||
import {fromJS} from "immutable" | ||
import Seamless from "seamless-immutable" | ||
import deepFreeze from "deep-freeze" | ||
|
||
enableAllPlugins() | ||
|
||
console.log("\n# add-data - loading large set of data\n") | ||
|
||
const dataSet = require("./data.json") | ||
const baseState = { | ||
data: null | ||
data: null | ||
} | ||
const frozenBazeState = deepFreeze(cloneDeep(baseState)) | ||
const immutableJsBaseState = fromJS(baseState) | ||
const seamlessBaseState = Seamless.from(baseState) | ||
|
||
const MAX = 10000 | ||
|
||
measure( | ||
"just mutate", | ||
() => ({draft: cloneDeep(baseState)}), | ||
({draft}) => { | ||
draft.data = dataSet | ||
} | ||
"just mutate", | ||
() => ({draft: cloneDeep(baseState)}), | ||
({draft}) => { | ||
draft.data = dataSet | ||
} | ||
) | ||
|
||
measure( | ||
"just mutate, freeze", | ||
() => ({draft: cloneDeep(baseState)}), | ||
({draft}) => { | ||
draft.data = dataSet | ||
deepFreeze(draft) | ||
} | ||
"just mutate, freeze", | ||
() => ({draft: cloneDeep(baseState)}), | ||
({draft}) => { | ||
draft.data = dataSet | ||
deepFreeze(draft) | ||
} | ||
) | ||
|
||
measure("handcrafted reducer (no freeze)", () => { | ||
const nextState = { | ||
...baseState, | ||
data: dataSet | ||
} | ||
const nextState = { | ||
...baseState, | ||
data: dataSet | ||
} | ||
}) | ||
|
||
measure("handcrafted reducer (with freeze)", () => { | ||
const nextState = deepFreeze({ | ||
...baseState, | ||
data: dataSet | ||
}) | ||
const nextState = deepFreeze({ | ||
...baseState, | ||
data: dataSet | ||
}) | ||
}) | ||
|
||
measure("immutableJS", () => { | ||
let state = immutableJsBaseState.withMutations(state => { | ||
state.setIn(["data"], fromJS(dataSet)) | ||
}) | ||
let state = immutableJsBaseState.withMutations(state => { | ||
state.setIn(["data"], fromJS(dataSet)) | ||
}) | ||
}) | ||
|
||
measure("immutableJS + toJS", () => { | ||
let state = immutableJsBaseState | ||
.withMutations(state => { | ||
state.setIn(["data"], fromJS(dataSet)) | ||
}) | ||
.toJS() | ||
let state = immutableJsBaseState | ||
.withMutations(state => { | ||
state.setIn(["data"], fromJS(dataSet)) | ||
}) | ||
.toJS() | ||
}) | ||
|
||
measure("seamless-immutable", () => { | ||
seamlessBaseState.set("data", dataSet) | ||
seamlessBaseState.set("data", dataSet) | ||
}) | ||
|
||
measure("seamless-immutable + asMutable", () => { | ||
seamlessBaseState.set("data", dataSet).asMutable({deep: true}) | ||
seamlessBaseState.set("data", dataSet).asMutable({deep: true}) | ||
}) | ||
|
||
measure("immer (proxy) - without autofreeze", () => { | ||
setUseProxies(true) | ||
setAutoFreeze(false) | ||
produce(baseState, draft => { | ||
draft.data = dataSet | ||
}) | ||
measure("immer (proxy) - without autofreeze * " + MAX, () => { | ||
setUseProxies(true) | ||
setAutoFreeze(false) | ||
for (let i = 0; i < MAX; i++) | ||
produce(baseState, draft => { | ||
draft.data = dataSet | ||
}) | ||
}) | ||
|
||
measure("immer (proxy) - with autofreeze", () => { | ||
setUseProxies(true) | ||
setAutoFreeze(true) | ||
produce(frozenBazeState, draft => { | ||
draft.data = dataSet | ||
}) | ||
measure("immer (proxy) - with autofreeze * " + MAX, () => { | ||
setUseProxies(true) | ||
setAutoFreeze(true) | ||
for (let i = 0; i < MAX; i++) | ||
produce(frozenBazeState, draft => { | ||
draft.data = dataSet | ||
}) | ||
}) | ||
|
||
measure("immer (es5) - without autofreeze", () => { | ||
setUseProxies(false) | ||
setAutoFreeze(false) | ||
produce(baseState, draft => { | ||
draft.data = dataSet | ||
}) | ||
measure("immer (es5) - without autofreeze * " + MAX, () => { | ||
setUseProxies(false) | ||
setAutoFreeze(false) | ||
for (let i = 0; i < MAX; i++) | ||
produce(baseState, draft => { | ||
draft.data = dataSet | ||
}) | ||
}) | ||
|
||
measure("immer (es5) - with autofreeze", () => { | ||
setUseProxies(false) | ||
setAutoFreeze(true) | ||
produce(frozenBazeState, draft => { | ||
draft.data = dataSet | ||
}) | ||
measure("immer (es5) - with autofreeze * " + MAX, () => { | ||
setUseProxies(false) | ||
setAutoFreeze(true) | ||
for (let i = 0; i < MAX; i++) | ||
produce(frozenBazeState, draft => { | ||
draft.data = dataSet | ||
}) | ||
}) |
Oops, something went wrong.