common.js
This file
Path
src/common.js
33 lines · 1.0 KiB · JavaScript
Last changed by
One module to rule them all WIPMichel Weststratebefore adoptionb7647e4
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334export const PROXY_STATE = Symbol("immer-proxy-state") // TODO: create per closure, to avoid sharing proxies between multiple immer versionexport let autoFreeze = true
export function isProxy(value) { return !!value && !!value[PROXY_STATE]}
export function isProxyable(value) { if (!value) return false if (typeof value !== "object") return false if (Array.isArray(value)) return true const proto = Object.getPrototypeOf(value) return proto === null || proto === Object.prototype}
export function freeze(value) { if (autoFreeze) { Object.freeze(value) } return value}
/** * Automatically freezes any state trees generated by immer. * This protects against accidental modifications of the state tree outside of an immer function. * This comes with a performance impact, so it is recommended to disable this option in production. * It is by default enabled. * * @returns {void} */export function setAutoFreeze(enableAutoFreeze) { autoFreeze = enableAutoFreeze}