index.js
This file
Path
src/index.js
57 lines · 1.8 KiB · JavaScript
Last changed by
fix: applyPatches should mutate draftsaleclarsonbefore adoptiond41be77
History of this fileTake it
feat: add `Immer` classaleclarsonbefore adoptionecd04dc
lines 1–31why, one step back1import {Immer} from "./immer"23const immer = new Immer()45/**6 * The `produce` function takes a value and a "recipe function" (whose7 * return value often depends on the base state). The recipe function is8 * free to mutate its first argument however it wants. All mutations are9 * only ever applied to a __copy__ of the base state.10 *11 * Pass only a function to create a "curried producer" which relieves you12 * from passing the recipe function every time.13 *14 * Only plain objects and arrays are made mutable. All other objects are15 * considered uncopyable.16 *17 * Note: This function is __bound__ to its `Immer` instance.18 *19 * @param {any} base - the initial state20 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified21 * @param {Function} patchListener - optional function that will be called with all the patches produced here22 * @returns {any} a new state, or the initial state if nothing was modified23 */24export const produce = immer.produce25export default produce2627/**28 * Pass true to automatically freeze all copies created by Immer.29 *30 * By default, auto-freezing is disabled in production.31 */fix: applyPatches should mutate draftsaleclarsonbefore adoptiond41be77
line 32why, one step back32export const setAutoFreeze = immer.setAutoFreeze.bind(immer)feat: add `Immer` classaleclarsonbefore adoptionecd04dc
lines 33–39why, one step back3334/**35 * Pass true to use the ES2015 `Proxy` class when creating drafts, which is36 * always faster than using ES5 proxies.37 *38 * By default, feature detection is used, so calling this is rarely necessary.39 */fix: applyPatches should mutate draftsaleclarsonbefore adoptiond41be77
line 40why, one step back40export const setUseProxies = immer.setUseProxies.bind(immer)feat: add `Immer` classaleclarsonbefore adoptionecd04dc
lines 41–46why, one step back4142/**43 * Apply an array of Immer patches to the first argument.44 *45 * This function is a producer, which means copy-on-write is in effect.46 */fix: applyPatches should mutate draftsaleclarsonbefore adoptiond41be77
line 47why, one step back47export const applyPatches = immer.applyPatches.bind(immer)feat: add `Immer` classaleclarsonbefore adoptionecd04dc
line 48why, one step back48feat: limited class supportaleclarsonbefore adoption9877d64
lines 49–51why, one step back49export {50 original,51 isDraft,feat: export isDraftablealeclarsonbefore adoptionc89d47d
line 52why, one step back52 isDraftable,feat: limited class supportaleclarsonbefore adoption9877d64
lines 53–55why, one step back53 NOTHING as nothing,54 DRAFTABLE as immerable55} from "./common"feat: add `Immer` classaleclarsonbefore adoptionecd04dc
lines 56–57why, one step back5657export {Immer}