FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ionic/src/util/module-loader.ts at master · javascript2016/ionic · GitHub
javascript2016
ionic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ionic
/
src
/
util
/
module-loader.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (85 loc) · 3.11 KB
Breadcrumbs
ionic
/
src
/
util
/
module-loader.ts
Copy path
File metadata and controls
111 lines (85 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import
{
ComponentFactoryResolver
,
Injectable
,
InjectionToken
,
Injector
,
NgModuleFactory
,
NgZone
,
Type
}
from
'@angular/core'
;
import
{
Config
}
from
'../config/config'
;
import
{
DeepLinkConfig
}
from
'../navigation/nav-util'
;
import
{
NgModuleLoader
}
from
'./ng-module-loader'
;
import
{
requestIonicCallback
}
from
'./util'
;
export
const
LAZY_LOADED_TOKEN
=
new
InjectionToken
<
any
>
(
'LZYCMP'
)
;
/**
*
@hidden
*/
@
Injectable
(
)
export
class
ModuleLoader
{
/**
@internal
*/
_cfrMap
=
new
Map
<
any
,
ComponentFactoryResolver
>
(
)
;
_promiseMap
=
new
Map
<
string
,
Promise
<
NgModuleFactory
<
any
>
>
>
(
)
;
constructor
(
private
_ngModuleLoader
:
NgModuleLoader
,
private
_injector
:
Injector
)
{
}
load
(
modulePath
:
string
)
:
Promise
<
LoadedModule
>
{
console
.
time
(
`ModuleLoader, load:
${
modulePath
}
'`
)
;
const
splitString
=
modulePath
.
split
(
SPLITTER
)
;
let
promise
=
this
.
_promiseMap
.
get
(
modulePath
)
;
if
(
!
promise
)
{
promise
=
this
.
_ngModuleLoader
.
load
(
splitString
[
0
]
,
splitString
[
1
]
)
;
this
.
_promiseMap
.
set
(
modulePath
,
promise
)
;
}
return
promise
.
then
(
loadedModule
=>
{
console
.
timeEnd
(
`ModuleLoader, load:
${
modulePath
}
'`
)
;
const
ref
=
loadedModule
.
create
(
this
.
_injector
)
;
const
component
=
ref
.
injector
.
get
(
LAZY_LOADED_TOKEN
)
;
this
.
_cfrMap
.
set
(
component
,
ref
.
componentFactoryResolver
)
;
return
{
componentFactoryResolver
:
ref
.
componentFactoryResolver
,
component
:
component
}
;
}
)
;
}
getComponentFactoryResolver
(
component
:
Type
<
any
>
)
{
return
this
.
_cfrMap
.
get
(
component
)
;
}
}
const
SPLITTER
=
'#'
;
/**
*
@hidden
*/
export
function
provideModuleLoader
(
ngModuleLoader
:
NgModuleLoader
,
injector
:
Injector
)
{
return
new
ModuleLoader
(
ngModuleLoader
,
injector
)
;
}
export
interface
LoadedModule
{
componentFactoryResolver
:
ComponentFactoryResolver
;
component
:
Type
<
any
>
;
}
/**
*
@hidden
*/
export
function
setupPreloadingImplementation
(
config
:
Config
,
deepLinkConfig
:
DeepLinkConfig
,
moduleLoader
:
ModuleLoader
)
:
Promise
<
any
>
{
if
(
!
deepLinkConfig
||
!
deepLinkConfig
.
links
||
!
config
.
getBoolean
(
'preloadModules'
)
)
{
return
Promise
.
resolve
(
)
;
}
const
linksToLoad
=
deepLinkConfig
.
links
.
filter
(
link
=>
!
!
link
.
loadChildren
&&
link
.
priority
!==
'off'
)
;
// Load the high priority modules first
const
highPriorityPromises
=
linksToLoad
.
filter
(
link
=>
link
.
priority
===
'high'
)
.
map
(
link
=>
moduleLoader
.
load
(
link
.
loadChildren
)
)
;
return
Promise
.
all
(
highPriorityPromises
)
.
then
(
(
)
=>
{
// Load the low priority modules after the high priority are done
const
lowPriorityPromises
=
linksToLoad
.
filter
(
link
=>
link
.
priority
===
'low'
)
.
map
(
link
=>
moduleLoader
.
load
(
link
.
loadChildren
)
)
;
return
Promise
.
all
(
lowPriorityPromises
)
;
}
)
.
catch
(
err
=>
{
console
.
error
(
err
.
message
)
;
}
)
;
}
/**
*
@hidden
*/
export
function
setupPreloading
(
config
:
Config
,
deepLinkConfig
:
DeepLinkConfig
,
moduleLoader
:
ModuleLoader
,
ngZone
:
NgZone
)
{
return
function
(
)
{
requestIonicCallback
(
(
)
=>
{
ngZone
.
runOutsideAngular
(
(
)
=>
{
setupPreloadingImplementation
(
config
,
deepLinkConfig
,
moduleLoader
)
;
}
)
;
}
)
;
}
;
}
Back
|
FazBrowse Home
|
New Git URL