Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+10 added−9 removed
other:+10 added−9 removed
Provenance
Commit
ff25a83
Tree
a0bdaf5
Author
Andrey Boldyrev <runnez@yandex.ru>
Committer
Andrey Boldyrev <runnez@yandex.ru>
Parent
741e941
2 files changed+10 added−9 removed
modified:src/common.js+2 added
219 unmodified lines
220221export function clone(obj) {222 if (!isDraftable(obj)) return obj223 if (Array.isArray(obj)) return obj.map(clone)224+ if (isMap(obj)) return new Map(obj)225+ if (isSet(obj)) return new Set(obj)226 const cloned = Object.create(Object.getPrototypeOf(obj))227 for (const key in obj) cloned[key] = clone(obj[key])228 return cloned229}
7 unmodified lines
modified:src/patches.js+8 added-9 removed
127 unmodified lines
Expand all
128
129
130
131
132
132
133
134
135
2 unmodified lines
138
139
140
141
142
143
144
145
146
147
148
148
149
150
149
150
151
152
153
154
155
156
153
154
155
156
157
157
158
159
160
22 unmodified lines
127 unmodified lines
Expand all
export const applyPatches = (draft, patches) => {
for (const patch of patches) {
const {path, op} = patch
const value = clone(patch.value) // used to clone patch to ensure original patch is not modified, see #411
if (!path.length) throw new Error("Illegal state")