@@ -30,21 +30,10 @@ export function willFinalize(result, baseDraft, needPatches) {
30
30
}
31
31
32
32
export function createDraft ( base , parent ) {
33
- let draft
34
- if ( isDraft ( base ) ) {
35
- const state = base [ DRAFT_STATE ]
36
- // Avoid creating new drafts when copying.
37
- state . finalizing = true
38
- draft = shallowCopy ( state . draft , true )
39
- state . finalizing = false
40
- } else {
41
- draft = shallowCopy ( base )
42
- }
43
-
44
33
const isArray = Array . isArray ( base )
34
+ const draft = clonePotentialDraft ( base )
45
35
eachOwn ( draft , prop => {
46
- const enumerable = isArray || isEnumerable ( base , prop )
47
- proxyProperty ( draft , prop , enumerable )
36
+ proxyProperty ( draft , prop , isArray || isEnumerable ( base , prop ) )
48
37
} )
49
38
50
39
// See "proxy.js" for property documentation.
@@ -105,7 +94,18 @@ function markChanged(state) {
105
94
}
106
95
107
96
function prepareCopy ( state ) {
108
- if ( ! state . copy ) state . copy = shallowCopy ( state . base )
97
+ if ( ! state . copy ) state . copy = clonePotentialDraft ( state . base )
98
+ }
99
+
100
+ function clonePotentialDraft ( base ) {
101
+ const state = base && base [ DRAFT_STATE ]
102
+ if ( state ) {
103
+ state . finalizing = true
104
+ const draft = shallowCopy ( state . draft , true )
105
+ state . finalizing = false
106
+ return draft
107
+ }
108
+ return shallowCopy ( base )
109
109
}
110
110
111
111
function proxyProperty ( draft , prop , enumerable ) {
0 commit comments