1
- var util = require ( './util' )
1
+ import { getRouteConfig , resolveAsyncComponent } from './util'
2
2
3
3
/**
4
4
* Determine the reusability of an existing router view.
@@ -8,8 +8,8 @@ var util = require('./util')
8
8
* @param {Transition } transition
9
9
*/
10
10
11
- exports . canReuse = function ( view , handler , transition ) {
12
- var component = view . childVM
11
+ export function canReuse ( view , handler , transition ) {
12
+ let component = view . childVM
13
13
if ( ! component || ! handler ) {
14
14
return false
15
15
}
@@ -18,7 +18,7 @@ exports.canReuse = function (view, handler, transition) {
18
18
if ( view . Component !== handler . component ) {
19
19
return false
20
20
}
21
- var canReuseFn = util . getRouteConfig ( component , 'canReuse' )
21
+ let canReuseFn = getRouteConfig ( component , 'canReuse' )
22
22
return typeof canReuseFn === 'boolean'
23
23
? canReuseFn
24
24
: canReuseFn
@@ -37,9 +37,9 @@ exports.canReuse = function (view, handler, transition) {
37
37
* @param {Function } next
38
38
*/
39
39
40
- exports . canDeactivate = function ( view , transition , next ) {
41
- var fromComponent = view . childVM
42
- var hook = util . getRouteConfig ( fromComponent , 'canDeactivate' )
40
+ export function canDeactivate ( view , transition , next ) {
41
+ let fromComponent = view . childVM
42
+ let hook = getRouteConfig ( fromComponent , 'canDeactivate' )
43
43
if ( ! hook ) {
44
44
next ( )
45
45
} else {
@@ -55,14 +55,14 @@ exports.canDeactivate = function (view, transition, next) {
55
55
* @param {Function } next
56
56
*/
57
57
58
- exports . canActivate = function ( handler , transition , next ) {
59
- util . resolveAsyncComponent ( handler , function ( Component ) {
58
+ export function canActivate ( handler , transition , next ) {
59
+ resolveAsyncComponent ( handler , ( Component ) => {
60
60
// have to check due to async-ness
61
61
if ( transition . aborted ) {
62
62
return
63
63
}
64
64
// determine if this component can be activated
65
- var hook = util . getRouteConfig ( Component , 'canActivate' )
65
+ let hook = getRouteConfig ( Component , 'canActivate' )
66
66
if ( ! hook ) {
67
67
next ( )
68
68
} else {
@@ -79,9 +79,9 @@ exports.canActivate = function (handler, transition, next) {
79
79
* @param {Function } next
80
80
*/
81
81
82
- exports . deactivate = function ( view , transition , next ) {
83
- var component = view . childVM
84
- var hook = util . getRouteConfig ( component , 'deactivate' )
82
+ export function deactivate ( view , transition , next ) {
83
+ let component = view . childVM
84
+ let hook = getRouteConfig ( component , 'deactivate' )
85
85
if ( ! hook ) {
86
86
next ( )
87
87
} else {
@@ -98,40 +98,40 @@ exports.deactivate = function (view, transition, next) {
98
98
* @param {Function } [cb]
99
99
*/
100
100
101
- exports . activate = function ( view , transition , depth , cb ) {
102
- var handler = transition . activateQueue [ depth ]
101
+ export function activate ( view , transition , depth , cb ) {
102
+ let handler = transition . activateQueue [ depth ]
103
103
if ( ! handler ) {
104
104
view . setComponent ( null )
105
105
cb && cb ( )
106
106
return
107
107
}
108
108
109
- var Component = view . Component = handler . component
110
- var activateHook = util . getRouteConfig ( Component , 'activate' )
111
- var dataHook = util . getRouteConfig ( Component , 'data' )
112
- var waitForData = util . getRouteConfig ( Component , 'waitForData' )
109
+ let Component = view . Component = handler . component
110
+ let activateHook = getRouteConfig ( Component , 'activate' )
111
+ let dataHook = getRouteConfig ( Component , 'data' )
112
+ let waitForData = getRouteConfig ( Component , 'waitForData' )
113
113
114
114
// unbuild current component. this step also destroys
115
115
// and removes all nested child views.
116
116
view . unbuild ( true )
117
117
// build the new component. this will also create the
118
118
// direct child view of the current one. it will register
119
119
// itself as view.childView.
120
- var component = view . build ( {
120
+ let component = view . build ( {
121
121
_meta : {
122
122
$loadingRouteData : ! ! ( dataHook && ! waitForData )
123
123
}
124
124
} )
125
125
126
126
// cleanup the component in case the transition is aborted
127
127
// before the component is ever inserted.
128
- var cleanup = function ( ) {
128
+ let cleanup = ( ) => {
129
129
component . $destroy ( )
130
130
}
131
131
132
132
// actually insert the component and trigger transition
133
- var insert = function ( ) {
134
- var router = transition . router
133
+ let insert = ( ) => {
134
+ let router = transition . router
135
135
if ( router . _rendered || router . _transitionOnLoad ) {
136
136
view . transition ( component )
137
137
} else {
@@ -143,7 +143,7 @@ exports.activate = function (view, transition, depth, cb) {
143
143
}
144
144
145
145
// called after activation hook is resolved
146
- var afterActivate = function ( ) {
146
+ let afterActivate = ( ) => {
147
147
// activate the child view
148
148
if ( view . childView ) {
149
149
exports . activate ( view . childView , transition , depth + 1 )
@@ -174,9 +174,9 @@ exports.activate = function (view, transition, depth, cb) {
174
174
* @param {Transition } transition
175
175
*/
176
176
177
- exports . reuse = function ( view , transition ) {
178
- var component = view . childVM
179
- var dataHook = util . getRouteConfig ( component , 'data' )
177
+ export function reuse ( view , transition ) {
178
+ let component = view . childVM
179
+ let dataHook = getRouteConfig ( component , 'data' )
180
180
if ( dataHook ) {
181
181
loadData ( component , transition , dataHook )
182
182
}
@@ -194,8 +194,8 @@ exports.reuse = function (view, transition) {
194
194
195
195
function loadData ( component , transition , hook , cb , cleanup ) {
196
196
component . $loadingRouteData = true
197
- transition . callHook ( hook , component , function ( data ) {
198
- for ( var key in data ) {
197
+ transition . callHook ( hook , component , ( data ) => {
198
+ for ( let key in data ) {
199
199
component . $set ( key , data [ key ] )
200
200
}
201
201
component . $loadingRouteData = false
0 commit comments