@@ -51,17 +51,33 @@ if ((<any>global).___TS_UNUSED) {
51
51
} ) ( ) ;
52
52
}
53
53
54
+ // tslint:disable:max-line-length
55
+ /**
56
+ * Options to be passed when HMR is enabled
57
+ */
54
58
export interface HmrOptions {
59
+ /**
60
+ * A factory function that returns either Module type or NgModuleFactory type.
61
+ * This needs to be a factory function as the types will change when modules are replaced.
62
+ */
55
63
moduleTypeFactory ?: ( ) => Type < any > | NgModuleFactory < any > ;
56
- livesyncCallback : ( bootstrapPlatfrom : ( ) => void ) => void ;
64
+
65
+ /**
66
+ * A livesync callback that will be called instead of the original livesync.
67
+ * It gives the HMR a hook to apply the module replacement.
68
+ * @param bootstrapPlatform - A bootstrap callback to be called after HMR is done. It will bootstrap a new angular app within the exisiting platform, using the moduleTypeFactory to get the Module or NgModuleFactory to be used.
69
+ */
70
+ livesyncCallback : ( bootstrapPlatform : ( ) => void ) => void ;
57
71
}
72
+ // tslint:enable:max-line-length
73
+
58
74
59
75
export interface AppOptions {
60
76
bootInExistingPage ?: boolean ;
61
77
cssFile ?: string ;
62
78
startPageActionBarHidden ?: boolean ;
63
79
createFrameOnBootstrap ?: boolean ;
64
- hmr ?: HmrOptions ;
80
+ hmrOptions ?: HmrOptions ;
65
81
}
66
82
67
83
export type PlatformFactory = ( extraProviders ?: StaticProvider [ ] ) => PlatformRef ;
@@ -98,9 +114,14 @@ export class NativeScriptPlatformRef extends PlatformRef {
98
114
99
115
@profile
100
116
bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
101
- this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory (
102
- this . appOptions . hmr ? < NgModuleFactory < M > > this . appOptions . hmr . moduleTypeFactory ( ) : moduleFactory
103
- ) ;
117
+ this . _bootstrapper = ( ) => {
118
+ let bootstrapFactory = moduleFactory ;
119
+ if ( this . appOptions . hmrOptions ) {
120
+ bootstrapFactory = < NgModuleFactory < M > > this . appOptions . hmrOptions . moduleTypeFactory ( ) ;
121
+ }
122
+
123
+ return this . platform . bootstrapModuleFactory ( bootstrapFactory ) ;
124
+ } ;
104
125
105
126
this . bootstrapApp ( ) ;
106
127
@@ -112,10 +133,14 @@ export class NativeScriptPlatformRef extends PlatformRef {
112
133
moduleType : Type < M > ,
113
134
compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ]
114
135
) : Promise < NgModuleRef < M > > {
115
- this . _bootstrapper = ( ) => this . platform . bootstrapModule (
116
- this . appOptions . hmr ? < Type < M > > this . appOptions . hmr . moduleTypeFactory ( ) : moduleType ,
117
- compilerOptions ) ;
136
+ this . _bootstrapper = ( ) => {
137
+ let bootstrapType = moduleType ;
138
+ if ( this . appOptions . hmrOptions ) {
139
+ bootstrapType = < Type < M > > this . appOptions . hmrOptions . moduleTypeFactory ( ) ;
140
+ }
118
141
142
+ return this . platform . bootstrapModule ( bootstrapType , compilerOptions ) ;
143
+ } ;
119
144
this . bootstrapApp ( ) ;
120
145
121
146
return null ; // Make the compiler happy
@@ -124,8 +149,8 @@ export class NativeScriptPlatformRef extends PlatformRef {
124
149
@profile
125
150
private bootstrapApp ( ) {
126
151
( < any > global ) . __onLiveSyncCore = ( ) => {
127
- if ( this . appOptions . hmr ) {
128
- this . appOptions . hmr . livesyncCallback ( ( ) => this . _livesync ( ) ) ;
152
+ if ( this . appOptions . hmrOptions ) {
153
+ this . appOptions . hmrOptions . livesyncCallback ( ( ) => this . _livesync ( ) ) ;
129
154
} else {
130
155
this . _livesync ( ) ;
131
156
}
0 commit comments