1
1
exports . sync = function ( store , router , options ) {
2
- var moduleName = ( options || { } ) . moduleName || 'route'
2
+ const moduleName = ( options || { } ) . moduleName || 'route'
3
3
4
4
store . registerModule ( moduleName , {
5
5
namespaced : true ,
6
6
state : cloneRoute ( router . currentRoute ) ,
7
7
mutations : {
8
- 'ROUTE_CHANGED' : function ( state , transition ) {
8
+ 'ROUTE_CHANGED' ( state , transition ) {
9
9
store . state [ moduleName ] = cloneRoute ( transition . to , transition . from )
10
10
}
11
11
}
12
12
} )
13
13
14
- var isTimeTraveling = false
15
- var currentPath
14
+ let isTimeTraveling = false
15
+ let currentPath
16
16
17
17
// sync router on store change
18
- var storeUnwatch = store . watch (
19
- function ( state ) { return state [ moduleName ] } ,
20
- function ( route ) {
21
- var fullPath = route . fullPath
18
+ const storeUnwatch = store . watch (
19
+ state => state [ moduleName ] ,
20
+ route => {
21
+ const { fullPath } = route
22
22
if ( fullPath === currentPath ) {
23
23
return
24
24
}
@@ -32,13 +32,13 @@ exports.sync = function (store, router, options) {
32
32
)
33
33
34
34
// sync store on router navigation
35
- var afterEachUnHook = router . afterEach ( function ( to , from ) {
35
+ const afterEachUnHook = router . afterEach ( ( to , from ) => {
36
36
if ( isTimeTraveling ) {
37
37
isTimeTraveling = false
38
38
return
39
39
}
40
40
currentPath = to . fullPath
41
- store . commit ( moduleName + '/ROUTE_CHANGED' , { to : to , from : from } )
41
+ store . commit ( moduleName + '/ROUTE_CHANGED' , { to, from } )
42
42
} )
43
43
44
44
return function unsync ( ) {
@@ -58,7 +58,7 @@ exports.sync = function (store, router, options) {
58
58
}
59
59
60
60
function cloneRoute ( to , from ) {
61
- var clone = {
61
+ const clone = {
62
62
name : to . name ,
63
63
path : to . path ,
64
64
hash : to . hash ,
0 commit comments