@@ -50,11 +50,18 @@ if ((<any>global).___TS_UNUSED) {
50
50
return InjectionToken ;
51
51
} ) ( ) ;
52
52
}
53
+
54
+ export interface HmrOptions {
55
+ moduleTypeFactory ?: ( ) => Type < any > | NgModuleFactory < any >
56
+ livesyncCallback : ( bootstrapPlatfrom : ( ) => void ) => void ;
57
+ }
58
+
53
59
export interface AppOptions {
54
60
bootInExistingPage ?: boolean ;
55
61
cssFile ?: string ;
56
62
startPageActionBarHidden ?: boolean ;
57
63
createFrameOnBootstrap ?: boolean ;
64
+ hmr ?: HmrOptions ;
58
65
}
59
66
60
67
export type PlatformFactory = ( extraProviders ?: StaticProvider [ ] ) => PlatformRef ;
@@ -91,7 +98,9 @@ export class NativeScriptPlatformRef extends PlatformRef {
91
98
92
99
@profile
93
100
bootstrapModuleFactory < M > ( moduleFactory : NgModuleFactory < M > ) : Promise < NgModuleRef < M > > {
94
- this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory ( moduleFactory ) ;
101
+ this . _bootstrapper = ( ) => this . platform . bootstrapModuleFactory (
102
+ this . appOptions . hmr ? < NgModuleFactory < M > > this . appOptions . hmr . moduleTypeFactory ( ) : moduleFactory
103
+ ) ;
95
104
96
105
this . bootstrapApp ( ) ;
97
106
@@ -103,7 +112,9 @@ export class NativeScriptPlatformRef extends PlatformRef {
103
112
moduleType : Type < M > ,
104
113
compilerOptions : CompilerOptions | CompilerOptions [ ] = [ ]
105
114
) : Promise < NgModuleRef < M > > {
106
- this . _bootstrapper = ( ) => this . platform . bootstrapModule ( moduleType , compilerOptions ) ;
115
+ this . _bootstrapper = ( ) => this . platform . bootstrapModule (
116
+ this . appOptions . hmr ? < Type < M > > this . appOptions . hmr . moduleTypeFactory ( ) : moduleType ,
117
+ compilerOptions ) ;
107
118
108
119
this . bootstrapApp ( ) ;
109
120
@@ -113,7 +124,11 @@ export class NativeScriptPlatformRef extends PlatformRef {
113
124
@profile
114
125
private bootstrapApp ( ) {
115
126
( < any > global ) . __onLiveSyncCore = ( ) => {
116
- this . _livesync ( ) ;
127
+ if ( this . appOptions . hmr ) {
128
+ this . appOptions . hmr . livesyncCallback ( ( ) => this . _livesync ( ) ) ;
129
+ } else {
130
+ this . _livesync ( ) ;
131
+ }
117
132
} ;
118
133
119
134
if ( this . appOptions && typeof this . appOptions . cssFile === "string" ) {
@@ -224,7 +239,12 @@ export class NativeScriptPlatformRef extends PlatformRef {
224
239
if ( isLogEnabled ( ) ) {
225
240
bootstrapLog ( "Angular livesync started." ) ;
226
241
}
227
- onBeforeLivesync . next ( lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null ) ;
242
+
243
+ const lastModuleRef = lastBootstrappedModule ? lastBootstrappedModule . get ( ) : null
244
+ onBeforeLivesync . next ( lastModuleRef ) ;
245
+ if ( lastModuleRef ) {
246
+ lastModuleRef . destroy ( ) ;
247
+ }
228
248
229
249
const autoCreateFrame = ! ! this . appOptions . createFrameOnBootstrap ;
230
250
let tempAppHostView : AppHostView ;
0 commit comments