1- var util = require ( './util' )
1+ import { getRouteConfig , resolveAsyncComponent } from './util'
22
33/**
44 * Determine the reusability of an existing router view.
@@ -8,8 +8,8 @@ var util = require('./util')
88 * @param {Transition } transition
99 */
1010
11- exports . canReuse = function ( view , handler , transition ) {
12- var component = view . childVM
11+ export function canReuse ( view , handler , transition ) {
12+ let component = view . childVM
1313 if ( ! component || ! handler ) {
1414 return false
1515 }
@@ -18,7 +18,7 @@ exports.canReuse = function (view, handler, transition) {
1818 if ( view . Component !== handler . component ) {
1919 return false
2020 }
21- var canReuseFn = util . getRouteConfig ( component , 'canReuse' )
21+ let canReuseFn = getRouteConfig ( component , 'canReuse' )
2222 return typeof canReuseFn === 'boolean'
2323 ? canReuseFn
2424 : canReuseFn
@@ -37,9 +37,9 @@ exports.canReuse = function (view, handler, transition) {
3737 * @param {Function } next
3838 */
3939
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' )
4343 if ( ! hook ) {
4444 next ( )
4545 } else {
@@ -55,14 +55,14 @@ exports.canDeactivate = function (view, transition, next) {
5555 * @param {Function } next
5656 */
5757
58- exports . canActivate = function ( handler , transition , next ) {
59- util . resolveAsyncComponent ( handler , function ( Component ) {
58+ export function canActivate ( handler , transition , next ) {
59+ resolveAsyncComponent ( handler , ( Component ) => {
6060 // have to check due to async-ness
6161 if ( transition . aborted ) {
6262 return
6363 }
6464 // determine if this component can be activated
65- var hook = util . getRouteConfig ( Component , 'canActivate' )
65+ let hook = getRouteConfig ( Component , 'canActivate' )
6666 if ( ! hook ) {
6767 next ( )
6868 } else {
@@ -79,9 +79,9 @@ exports.canActivate = function (handler, transition, next) {
7979 * @param {Function } next
8080 */
8181
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' )
8585 if ( ! hook ) {
8686 next ( )
8787 } else {
@@ -98,40 +98,40 @@ exports.deactivate = function (view, transition, next) {
9898 * @param {Function } [cb]
9999 */
100100
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 ]
103103 if ( ! handler ) {
104104 view . setComponent ( null )
105105 cb && cb ( )
106106 return
107107 }
108108
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' )
113113
114114 // unbuild current component. this step also destroys
115115 // and removes all nested child views.
116116 view . unbuild ( true )
117117 // build the new component. this will also create the
118118 // direct child view of the current one. it will register
119119 // itself as view.childView.
120- var component = view . build ( {
120+ let component = view . build ( {
121121 _meta : {
122122 $loadingRouteData : ! ! ( dataHook && ! waitForData )
123123 }
124124 } )
125125
126126 // cleanup the component in case the transition is aborted
127127 // before the component is ever inserted.
128- var cleanup = function ( ) {
128+ let cleanup = ( ) => {
129129 component . $destroy ( )
130130 }
131131
132132 // actually insert the component and trigger transition
133- var insert = function ( ) {
134- var router = transition . router
133+ let insert = ( ) => {
134+ let router = transition . router
135135 if ( router . _rendered || router . _transitionOnLoad ) {
136136 view . transition ( component )
137137 } else {
@@ -143,7 +143,7 @@ exports.activate = function (view, transition, depth, cb) {
143143 }
144144
145145 // called after activation hook is resolved
146- var afterActivate = function ( ) {
146+ let afterActivate = ( ) => {
147147 // activate the child view
148148 if ( view . childView ) {
149149 exports . activate ( view . childView , transition , depth + 1 )
@@ -174,9 +174,9 @@ exports.activate = function (view, transition, depth, cb) {
174174 * @param {Transition } transition
175175 */
176176
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' )
180180 if ( dataHook ) {
181181 loadData ( component , transition , dataHook )
182182 }
@@ -194,8 +194,8 @@ exports.reuse = function (view, transition) {
194194
195195function loadData ( component , transition , hook , cb , cleanup ) {
196196 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 ) {
199199 component . $set ( key , data [ key ] )
200200 }
201201 component . $loadingRouteData = false
0 commit comments