Comparing version 9.0.3 to 9.0.4
{ | ||
"name": "immer", | ||
"version": "9.0.3", | ||
"version": "9.0.4", | ||
"description": "Create your next immutable state by mutating the current one", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,4 +11,3 @@ import { | ||
isDraftable, | ||
ArchtypeMap, | ||
ArchtypeSet, | ||
Archtype, | ||
getArchtype, | ||
@@ -49,3 +48,3 @@ getPlugin | ||
// In the future, we might consider freezing here, based on the current settings | ||
return archType === ArchtypeSet ? new Set(copy) : copy | ||
return archType === Archtype.Set ? new Set(copy) : copy | ||
} | ||
@@ -56,5 +55,5 @@ | ||
switch (archType) { | ||
case ArchtypeMap: | ||
case Archtype.Map: | ||
return new Map(value) | ||
case ArchtypeSet: | ||
case Archtype.Set: | ||
// Set will be cloned as array temporarily, so that we can replace individual items | ||
@@ -61,0 +60,0 @@ return Array.from(value) |
@@ -14,5 +14,3 @@ import { | ||
set, | ||
ProxyTypeES5Object, | ||
ProxyTypeES5Array, | ||
ProxyTypeSet, | ||
ProxyType, | ||
getPlugin, | ||
@@ -88,3 +86,3 @@ die, | ||
// For ES5, create a good copy from the draft first, with added keys and without deleted keys. | ||
state.type_ === ProxyTypeES5Object || state.type_ === ProxyTypeES5Array | ||
state.type_ === ProxyType.ES5Object || state.type_ === ProxyType.ES5Array | ||
? (state.copy_ = shallowCopy(state.draft_)) | ||
@@ -97,3 +95,3 @@ : state.copy_ | ||
each( | ||
state.type_ === ProxyTypeSet ? new Set(result) : result, | ||
state.type_ === ProxyType.Set ? new Set(result) : result, | ||
(key, childValue) => | ||
@@ -130,3 +128,3 @@ finalizeProperty(rootScope, state, result, key, childValue, path) | ||
parentState && | ||
parentState!.type_ !== ProxyTypeSet && // Set objects are atomic since they have no keys. | ||
parentState!.type_ !== ProxyType.Set && // Set objects are atomic since they have no keys. | ||
!has((parentState as Exclude<ImmerState, SetState>).assigned_!, prop) // Skip deep patches for assigned keys. | ||
@@ -133,0 +131,0 @@ ? rootPath!.concat(prop) |
@@ -188,3 +188,3 @@ import { | ||
applyPatches<T extends Objectish>(base: Objectish, patches: Patch[]): T { | ||
applyPatches<T extends Objectish>(base: T, patches: Patch[]): T { | ||
// If a patch replaces the entire state, take that replacement as base | ||
@@ -191,0 +191,0 @@ // before applying patches |
@@ -18,4 +18,3 @@ import { | ||
createProxy, | ||
ProxyTypeProxyObject, | ||
ProxyTypeProxyArray | ||
ProxyType | ||
} from "../internal" | ||
@@ -32,3 +31,3 @@ | ||
export interface ProxyObjectState extends ProxyBaseState { | ||
type_: typeof ProxyTypeProxyObject | ||
type_: ProxyType.ProxyObject | ||
base_: any | ||
@@ -40,3 +39,3 @@ copy_: any | ||
export interface ProxyArrayState extends ProxyBaseState { | ||
type_: typeof ProxyTypeProxyArray | ||
type_: ProxyType.ProxyArray | ||
base_: AnyArray | ||
@@ -60,3 +59,3 @@ copy_: AnyArray | null | ||
const state: ProxyState = { | ||
type_: isArray ? ProxyTypeProxyArray : (ProxyTypeProxyObject as any), | ||
type_: isArray ? ProxyType.ProxyArray : (ProxyType.ProxyObject as any), | ||
// Track which produce call this is associated with. | ||
@@ -165,3 +164,10 @@ scope_: parent ? parent.scope_ : getCurrentScope()!, | ||
if (state.copy_![prop] === value && typeof value !== "number") return true | ||
if ( | ||
state.copy_![prop] === value && | ||
// special case: NaN | ||
typeof value !== "number" && | ||
// special case: handle new props with value 'undefined' | ||
(value !== undefined || prop in state.copy_) | ||
) | ||
return true | ||
@@ -195,3 +201,3 @@ // @ts-ignore | ||
writable: true, | ||
configurable: state.type_ !== ProxyTypeProxyArray || prop !== "length", | ||
configurable: state.type_ !== ProxyType.ProxyArray || prop !== "length", | ||
enumerable: desc.enumerable, | ||
@@ -198,0 +204,0 @@ value: owner[prop] |
@@ -8,4 +8,3 @@ import { | ||
ImmerState, | ||
ProxyTypeProxyObject, | ||
ProxyTypeProxyArray, | ||
ProxyType, | ||
getPlugin | ||
@@ -82,4 +81,4 @@ } from "../internal" | ||
if ( | ||
state.type_ === ProxyTypeProxyObject || | ||
state.type_ === ProxyTypeProxyArray | ||
state.type_ === ProxyType.ProxyObject || | ||
state.type_ === ProxyType.ProxyArray | ||
) | ||
@@ -86,0 +85,0 @@ state.revoke_() |
@@ -14,4 +14,3 @@ import { | ||
ImmerScope, | ||
ProxyTypeES5Array, | ||
ProxyTypeES5Object, | ||
ProxyType, | ||
getCurrentScope, | ||
@@ -78,3 +77,3 @@ die, | ||
const state: ES5ObjectState | ES5ArrayState = { | ||
type_: isArray ? ProxyTypeES5Array : (ProxyTypeES5Object as any), | ||
type_: isArray ? ProxyType.ES5Array : (ProxyType.ES5Object as any), | ||
scope_: parent ? parent.scope_ : getCurrentScope(), | ||
@@ -144,6 +143,6 @@ modified_: false, | ||
switch (state.type_) { | ||
case ProxyTypeES5Array: | ||
case ProxyType.ES5Array: | ||
if (hasArrayChanges(state)) markChanged(state) | ||
break | ||
case ProxyTypeES5Object: | ||
case ProxyType.ES5Object: | ||
if (hasObjectChanges(state)) markChanged(state) | ||
@@ -161,3 +160,3 @@ break | ||
const {base_, draft_, assigned_, type_} = state | ||
if (type_ === ProxyTypeES5Object) { | ||
if (type_ === ProxyType.ES5Object) { | ||
// Look for added keys. | ||
@@ -186,3 +185,3 @@ // probably there is a faster way to detect changes, as sweep + recurse seems to do some | ||
}) | ||
} else if (type_ === ProxyTypeES5Array) { | ||
} else if (type_ === ProxyType.ES5Array) { | ||
if (hasArrayChanges(state as ES5ArrayState)) { | ||
@@ -261,3 +260,3 @@ markChanged(state) | ||
function hasChanges_(state: ES5State) { | ||
return state.type_ === ProxyTypeES5Object | ||
return state.type_ === ProxyType.ES5Object | ||
? hasObjectChanges(state) | ||
@@ -264,0 +263,0 @@ : hasArrayChanges(state) |
@@ -16,4 +16,3 @@ // types only! | ||
markChanged, | ||
ProxyTypeMap, | ||
ProxyTypeSet, | ||
ProxyType, | ||
die, | ||
@@ -54,3 +53,3 @@ each | ||
this[DRAFT_STATE] = { | ||
type_: ProxyTypeMap, | ||
type_: ProxyType.Map, | ||
parent_: parent, | ||
@@ -213,3 +212,3 @@ scope_: parent ? parent.scope_ : getCurrentScope()!, | ||
this[DRAFT_STATE] = { | ||
type_: ProxyTypeSet, | ||
type_: ProxyType.Set, | ||
parent_: parent, | ||
@@ -216,0 +215,0 @@ scope_: parent ? parent.scope_ : getCurrentScope()!, |
@@ -19,15 +19,8 @@ import {immerable} from "../immer" | ||
loadPlugin, | ||
ProxyTypeProxyObject, | ||
ProxyTypeES5Object, | ||
ProxyTypeMap, | ||
ProxyTypeES5Array, | ||
ProxyTypeProxyArray, | ||
ProxyTypeSet, | ||
ArchtypeMap, | ||
ArchtypeSet, | ||
ArchtypeArray, | ||
ProxyType, | ||
Archtype, | ||
die, | ||
isDraft, | ||
isDraftable, | ||
ArchtypeObject | ||
NOTHING | ||
} from "../internal" | ||
@@ -47,5 +40,5 @@ | ||
switch (state.type_) { | ||
case ProxyTypeProxyObject: | ||
case ProxyTypeES5Object: | ||
case ProxyTypeMap: | ||
case ProxyType.ProxyObject: | ||
case ProxyType.ES5Object: | ||
case ProxyType.Map: | ||
return generatePatchesFromAssigned( | ||
@@ -57,6 +50,6 @@ state, | ||
) | ||
case ProxyTypeES5Array: | ||
case ProxyTypeProxyArray: | ||
case ProxyType.ES5Array: | ||
case ProxyType.ProxyArray: | ||
return generateArrayPatches(state, basePath, patches, inversePatches) | ||
case ProxyTypeSet: | ||
case ProxyType.Set: | ||
return generateSetPatches( | ||
@@ -204,3 +197,3 @@ (state as any) as SetState, | ||
path: [], | ||
value: replacement | ||
value: replacement === NOTHING ? undefined : replacement | ||
}) | ||
@@ -224,3 +217,3 @@ inversePatches.push({ | ||
if ( | ||
(parentType === ArchtypeObject || parentType === ArchtypeArray) && | ||
(parentType === Archtype.Object || parentType === Archtype.Array) && | ||
(p === "__proto__" || p === "constructor") | ||
@@ -240,6 +233,6 @@ ) | ||
switch (type) { | ||
case ArchtypeMap: | ||
case Archtype.Map: | ||
return base.set(key, value) | ||
/* istanbul ignore next */ | ||
case ArchtypeSet: | ||
case Archtype.Set: | ||
die(16) | ||
@@ -255,7 +248,7 @@ default: | ||
switch (type) { | ||
case ArchtypeArray: | ||
case Archtype.Array: | ||
return base.splice(key as any, 0, value) | ||
case ArchtypeMap: | ||
case Archtype.Map: | ||
return base.set(key, value) | ||
case ArchtypeSet: | ||
case Archtype.Set: | ||
return base.add(value) | ||
@@ -267,7 +260,7 @@ default: | ||
switch (type) { | ||
case ArchtypeArray: | ||
case Archtype.Array: | ||
return base.splice(key as any, 1) | ||
case ArchtypeMap: | ||
case Archtype.Map: | ||
return base.delete(key) | ||
case ArchtypeSet: | ||
case Archtype.Set: | ||
return base.delete(patch.value) | ||
@@ -274,0 +267,0 @@ default: |
@@ -20,13 +20,17 @@ import { | ||
export const ArchtypeObject = 0 | ||
export const ArchtypeArray = 1 | ||
export const ArchtypeMap = 2 | ||
export const ArchtypeSet = 3 | ||
export const enum Archtype { | ||
Object, | ||
Array, | ||
Map, | ||
Set | ||
} | ||
export const ProxyTypeProxyObject = 0 | ||
export const ProxyTypeProxyArray = 1 | ||
export const ProxyTypeES5Object = 4 | ||
export const ProxyTypeES5Array = 5 | ||
export const ProxyTypeMap = 2 | ||
export const ProxyTypeSet = 3 | ||
export const enum ProxyType { | ||
ProxyObject, | ||
ProxyArray, | ||
Map, | ||
Set, | ||
ES5Object, | ||
ES5Array | ||
} | ||
@@ -33,0 +37,0 @@ export interface ImmerBaseState { |
@@ -12,6 +12,3 @@ import { | ||
hasMap, | ||
ArchtypeObject, | ||
ArchtypeArray, | ||
ArchtypeMap, | ||
ArchtypeSet, | ||
Archtype, | ||
die | ||
@@ -51,4 +48,3 @@ } from "../internal" | ||
if (Ctor === Object) | ||
return true | ||
if (Ctor === Object) return true | ||
@@ -97,3 +93,3 @@ return ( | ||
export function each(obj: any, iter: any, enumerableOnly = false) { | ||
if (getArchtype(obj) === ArchtypeObject) { | ||
if (getArchtype(obj) === Archtype.Object) { | ||
;(enumerableOnly ? Object.keys : ownKeys)(obj).forEach(key => { | ||
@@ -108,3 +104,3 @@ if (!enumerableOnly || typeof key !== "symbol") iter(key, obj[key], obj) | ||
/*#__PURE__*/ | ||
export function getArchtype(thing: any): 0 | 1 | 2 | 3 { | ||
export function getArchtype(thing: any): Archtype { | ||
/* istanbul ignore next */ | ||
@@ -117,8 +113,8 @@ const state: undefined | ImmerState = thing[DRAFT_STATE] | ||
: Array.isArray(thing) | ||
? ArchtypeArray | ||
? Archtype.Array | ||
: isMap(thing) | ||
? ArchtypeMap | ||
? Archtype.Map | ||
: isSet(thing) | ||
? ArchtypeSet | ||
: ArchtypeObject | ||
? Archtype.Set | ||
: Archtype.Object | ||
} | ||
@@ -128,3 +124,3 @@ | ||
export function has(thing: any, prop: PropertyKey): boolean { | ||
return getArchtype(thing) === ArchtypeMap | ||
return getArchtype(thing) === Archtype.Map | ||
? thing.has(prop) | ||
@@ -137,3 +133,3 @@ : Object.prototype.hasOwnProperty.call(thing, prop) | ||
// @ts-ignore | ||
return getArchtype(thing) === ArchtypeMap ? thing.get(prop) : thing[prop] | ||
return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop] | ||
} | ||
@@ -144,4 +140,4 @@ | ||
const t = getArchtype(thing) | ||
if (t === ArchtypeMap) thing.set(propOrOldValue, value) | ||
else if (t === ArchtypeSet) { | ||
if (t === Archtype.Map) thing.set(propOrOldValue, value) | ||
else if (t === Archtype.Set) { | ||
thing.delete(propOrOldValue) | ||
@@ -148,0 +144,0 @@ thing.add(value) |
@@ -10,6 +10,3 @@ import { | ||
AnySet, | ||
ProxyTypeES5Array, | ||
ProxyTypeES5Object, | ||
ProxyTypeMap, | ||
ProxyTypeSet, | ||
ProxyType, | ||
die | ||
@@ -78,3 +75,3 @@ } from "../internal" | ||
export interface ES5ObjectState extends ES5BaseState { | ||
type_: typeof ProxyTypeES5Object | ||
type_: ProxyType.ES5Object | ||
draft_: Drafted<AnyObject, ES5ObjectState> | ||
@@ -86,3 +83,3 @@ base_: AnyObject | ||
export interface ES5ArrayState extends ES5BaseState { | ||
type_: typeof ProxyTypeES5Array | ||
type_: ProxyType.ES5Array | ||
draft_: Drafted<AnyObject, ES5ArrayState> | ||
@@ -96,3 +93,3 @@ base_: any | ||
export interface MapState extends ImmerBaseState { | ||
type_: typeof ProxyTypeMap | ||
type_: ProxyType.Map | ||
copy_: AnyMap | undefined | ||
@@ -106,3 +103,3 @@ assigned_: Map<any, boolean> | undefined | ||
export interface SetState extends ImmerBaseState { | ||
type_: typeof ProxyTypeSet | ||
type_: ProxyType.Set | ||
copy_: AnySet | undefined | ||
@@ -109,0 +106,0 @@ base_: AnySet |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
92693
23
2671
1