forked from lookfirst/ocLazyLoad-SystemJS-Router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (33 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
require('angular');
require('angular-ui-router');
require('ui-router-extras/release/modular/ct-ui-router-extras.core');
require('ui-router-extras/release/modular/ct-ui-router-extras.future');
require('oclazyload');
exports['default'] = function (angularModule, futureRoutes) {
angularModule.requires.push('ui.router', 'ct.ui.router.extras.core', 'ct.ui.router.extras.future', 'oc.lazyLoad');
// RouterConfig
return ['$ocLazyLoadProvider', '$stateProvider', '$futureStateProvider', function ($ocLazyLoadProvider, $stateProvider, $futureStateProvider) {
$futureStateProvider.stateFactory('load', ['$q', '$ocLazyLoad', 'futureState', function ($q, $ocLazyLoad, futureState) {
return $q.when(System['import'](futureState.src).then(function (loaded) {
// this is the angular module
if (loaded.name) {
return $ocLazyLoad.load(loaded);
}
// this is the ES6 default export
if (loaded.default) {
return $ocLazyLoad.load(loaded.default);
}
var keys = Object.keys(loaded);
return $ocLazyLoad.load(loaded[keys[0] === '__esModule' ? keys[1] : keys[0]]);
})).then(angular.noop);
}]);
futureRoutes.forEach(function (r) {
$futureStateProvider.futureState(r);
});
}];
};
module.exports = exports['default'];