Skip to content

Commit 7a7c011

Browse files
committed
Use strict iteration option
1 parent b2c6d59 commit 7a7c011

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/core/current.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,24 @@ function currentImpl(value: any): any {
2121
if (!isDraftable(value) || isFrozen(value)) return value
2222
const state: ImmerState | undefined = value[DRAFT_STATE]
2323
let copy: any
24+
let strict = true // Default to strict for compatibility
2425
if (state) {
2526
if (!state.modified_) return state.base_
2627
// Optimization: avoid generating new drafts during copying
2728
state.finalized_ = true
2829
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)
30+
strict = state.scope_.immer_.shouldUseStrictIteration(value)
2931
} else {
3032
copy = shallowCopy(value, true)
3133
}
3234
// recurse
33-
each(copy, (key, childValue) => {
34-
set(copy, key, currentImpl(childValue))
35-
})
35+
each(
36+
copy,
37+
(key, childValue) => {
38+
set(copy, key, currentImpl(childValue))
39+
},
40+
strict
41+
)
3642
if (state) {
3743
state.finalized_ = false
3844
}

src/core/finalize.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ function finalize(rootScope: ImmerScope, value: any, path?: PatchPath) {
5959
const state: ImmerState = value[DRAFT_STATE]
6060
// A plain object, might need freezing, might contain drafts
6161
if (!state) {
62-
each(value, (key, childValue) =>
63-
finalizeProperty(rootScope, state, value, key, childValue, path)
62+
each(
63+
value,
64+
(key, childValue) =>
65+
finalizeProperty(rootScope, state, value, key, childValue, path),
66+
rootScope.immer_.shouldUseStrictIteration(value)
6467
)
6568
return value
6669
}
@@ -87,8 +90,19 @@ function finalize(rootScope: ImmerScope, value: any, path?: PatchPath) {
8790
result.clear()
8891
isSet = true
8992
}
90-
each(resultEach, (key, childValue) =>
91-
finalizeProperty(rootScope, state, result, key, childValue, path, isSet)
93+
each(
94+
resultEach,
95+
(key, childValue) =>
96+
finalizeProperty(
97+
rootScope,
98+
state,
99+
result,
100+
key,
101+
childValue,
102+
path,
103+
isSet
104+
),
105+
rootScope.immer_.shouldUseStrictIteration(resultEach)
92106
)
93107
// everything inside is frozen, we can freeze here
94108
maybeFreeze(rootScope, result, false)

0 commit comments

Comments
 (0)