@@ -9,6 +9,9 @@ const isProd = process.env.NODE_ENV === 'production'
9
9
export function initVuexBackend ( hook , bridge , isLegacy ) {
10
10
const store = hook . store
11
11
12
+ const earlyModules = hook . flushStoreModules ( )
13
+ let initialState = clone ( store . state )
14
+
12
15
let snapshotsVm = null
13
16
const updateSnapshotsVm = ( state ) => {
14
17
snapshotsVm = new Vue ( {
@@ -19,27 +22,14 @@ export function initVuexBackend (hook, bridge, isLegacy) {
19
22
} )
20
23
}
21
24
22
- const getStateSnapshot = ( _store = store ) => clone ( _store . state )
23
-
24
25
let baseStateSnapshot , stateSnapshots , mutations , lastState
25
26
let registeredModules = { }
26
27
let allTimeModules = { }
27
28
28
- const earlyModules = hook . flushStoreModules ( )
29
-
30
- // Init additional state
31
- earlyModules . forEach ( ( { path, module, options } ) => {
32
- if ( ! options || options . preserveState !== true ) {
33
- const state = typeof module . state === 'function' ? module . state ( ) : module . state
34
- const parentState = path . length === 1 ? hook . initialStore . state : get ( hook . initialStore . state , path . slice ( 0 , - 1 ) )
35
- set ( parentState , path [ path . length - 1 ] , state )
36
- }
37
- } )
38
-
39
29
updateSnapshotsVm ( )
40
30
41
31
function reset ( stateSnapshot = null ) {
42
- baseStateSnapshot = stateSnapshot || getStateSnapshot ( hook . initialStore )
32
+ baseStateSnapshot = stateSnapshot || clone ( initialState )
43
33
mutations = [ ]
44
34
resetSnapshotCache ( )
45
35
}
@@ -199,7 +189,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
199
189
200
190
bridge . on ( 'vuex:import-state' , state => {
201
191
const parsed = parse ( state , true )
202
- hook . initialStore . state = parsed
192
+ initialState = parsed
203
193
reset ( )
204
194
hook . emit ( 'vuex:travel-to-state' , parsed )
205
195
bridge . send ( 'vuex:init' )
@@ -281,7 +271,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
281
271
tempAddedModules . push ( key )
282
272
origRegisterModule ( moduleInfo . path , {
283
273
...moduleInfo . module ,
284
- state : moduleInfo . state
274
+ state : clone ( moduleInfo . state )
285
275
} , moduleInfo . options )
286
276
updateSnapshotsVm ( store . state )
287
277
if ( ! isProd ) console . log ( 'replay register module' , moduleInfo )
@@ -319,7 +309,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
319
309
}
320
310
321
311
// Send final state after replay
322
- resultState = getStateSnapshot ( )
312
+ resultState = clone ( store . state )
323
313
}
324
314
325
315
lastState = resultState
@@ -338,7 +328,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
338
328
const { path, module, options, state } = registeredModules [ m ]
339
329
origRegisterModule ( path , {
340
330
...module ,
341
- state
331
+ state : clone ( state )
342
332
} , options )
343
333
if ( ! isProd ) console . log ( 'after replay register' , m )
344
334
} )
@@ -364,7 +354,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
364
354
function takeStateSnapshot ( index ) {
365
355
stateSnapshots . push ( {
366
356
index,
367
- state : getStateSnapshot ( )
357
+ state : clone ( store . state )
368
358
} )
369
359
// Delete old cached snapshots
370
360
if ( stateSnapshots . length > SharedData . cacheVuexSnapshotsLimit ) {
@@ -402,7 +392,7 @@ export function initVuexBackend (hook, bridge, isLegacy) {
402
392
const { path, module, options, state } = data
403
393
origRegisterModule ( path , {
404
394
...module ,
405
- state
395
+ state : clone ( state )
406
396
} , options )
407
397
registeredModules [ path . join ( '/' ) ] = data
408
398
}
0 commit comments