Default build includes both Proxy and ES5 implementation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent ed048e9 · Browse files · 7 files·+22 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+22 added−22 removed
- other:+22 added−22 removed
Provenance
- Commit
bd9c47b- Tree
6882022- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
ed048e9
7 files changed+22 added−22 removed
modified:__performance_tests__/todo.js+1 added-1 removed
1223456175 unmodified linesExpand all"use strict"import produceProxy, {setAutoFreeze as setAutoFreezeProxy} from "../"import produceProxy, {setAutoFreeze as setAutoFreezeProxy} from "../proxy"import produceEs5, {setAutoFreeze as setAutoFreezeEs5} from "../es5"import cloneDeep from "lodash.clonedeep"import {List, Record} from "immutable"import deepFreeze from "deep-freeze"175 unmodified linesExpand allmodified:src/es5.js+2 added-6 removed
13 unmodified lines14 * @param {any} baseState - the state to start with15 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified16 * @returns {any} a new state, or the base state if nothing was modified17 */18-function produce(baseState, producer) {18+export default function produce(baseState, producer) {19 // curried invocation20 if (arguments.length === 1) {21 const producer = baseState22 // prettier-ignore244 unmodified lines267 * It is by default enabled.268 *269 * @returns {void}270 */271-function setAutoFreeze(enableAutoFreeze) {271+export function setAutoFreeze(enableAutoFreeze) {272 autoFreeze = enableAutoFreeze273 }274-275-createHiddenProperty(exports, "__esModule", true)276-module.exports.default = produce277-module.exports.setAutoFreeze = setAutoFreezemodified:src/immer.js+2 added-8 removed
79 unmodified lines80 * @param {any} baseState - the state to start with81 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified82 * @returns {any} a new state, or the base state if nothing was modified83 */84-function produce(baseState, producer) {84+export default function produce(baseState, producer) {85 // curried invocation86 if (arguments.length === 1) {87 const producer = baseState88 // prettier-ignore177 unmodified lines266 * It is by default enabled.267 *268 * @returns {void}269 */270-function setAutoFreeze(enableAutoFreeze) {270+export function setAutoFreeze(enableAutoFreeze) {271 autoFreeze = enableAutoFreeze272 }273-274-Object.defineProperty(exports, "__esModule", {275- value: true276-})277-module.exports.default = produce278-module.exports.setAutoFreeze = setAutoFreezemodified:.gitignore+2 added-1 removed
56 unmodified lines57 # dotenv environment variables file58 .env59 60 .idea61-dist/61+dist/62+proxy.jsmodified:changelog.md+4 added
1 # Changelog2 3+### 0.6.04+5+The default import now bundles both the es5 and proxy implementation as a convenient default. For more optimal bundle sizes, import `immer/proxy` or `immer/es5`6+7 ### 0.5.08 9 * Make sure es5.js is transpiled10 57 unmodified linesmodified:package.json+3 added-2 removed
1 {2 "name": "immer",3 "version": "0.5.0",4 "description": "Create your next immutable state by mutating the current one",5- "main": "dist/immer.js",5+ "main": "dist/index.js",6 "types": "./index.d.ts",7 "scripts": {8 "test": "jest",9 "test:perf": "yarn build:babel && node --expose-gc node_modules/jest-cli/bin/jest.js --verbose --testRegex '__performance_tests__/.*'",10 "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",11 "build": "yarn build:babel && yarn build:umd",12- "build:babel": "cd src && babel -d ../dist immer.js && babel --no-babelrc --presets=es2015 -d ../dist es5.js",12+ "build:babel": "cd src && babel immer.js -o ../proxy.js && babel --no-babelrc --presets=es2015 -d ../dist *.js",13 "build:umd": "browserify dist/immer.js -o dist/immer.umd.js -s immer && browserify dist/es5.js -o dist/es5.umd.js -s immer",14 "prettier": "prettier \"*/**/*.js\" --ignore-path ./.prettierignore --write",15 "prepublish": "yarn build"16 },16 unmodified lines33 },34 "homepage": "https://github.com/mweststrate/immer#readme",35 "files": [36 "es5.js",37+ "proxy.js",38 "index.d.ts",39 "dist/"40 ],41 "devDependencies": {24 unmodified linesmodified:readme.md+8 added-4 removed
180 unmodified lines181 182 By default `produce` tries to use proxies for optimal performance.183 However, on older JavaScript engines `Proxy` is not available.184 For example, Microsoft Internet Explorer or React Native on Android.185-In these cases, import the ES5 compatibile implementation first, which is a bit slower (see below) but semantically equivalent:185+In such cases Immer will fallback to an ES5 compatible implementation which works identical, but is a bit slower.186+However, if you want to slim down your bundle, you could only include the Proxy based implementation by importing from `immer/proxy`.187 187-```javascript188-import immer from "immer/es5"189-```188+An overview of the available builds:189 190+Immer exposes its functionality in 3 different ways:191+* `import produce from "immer"`, the default, ships with both the Proxy and ES5 compatible implementation, and picks at runtime the best matching one. This is the most convenient, but adds the most to the bundle size (~2KB)192+* `import produce from "immer/proxy"`: This build is optimized for modern browser, which support Proxies and other modern language features, and doesn't polyfill things like `Symbol`. Use this if you are targetting a modern environment only193+* `import produce from "immer/es5"`: Only bundle the ES5 compatible implementation (which of course also works for modern browsers)194+195 ## More reducer examples196 197 Here are some typical reducer examples, take from the Redux [Immutable Update Patterns](https://redux.js.org/docs/recipes/reducers/ImmutableUpdatePatterns.html) page, and their Immer counter part.198 These examples are semantically equivalent and produce the exact same state.96 unmodified lines