Skip to content

Commit 8f09598

Browse files
author
vakrilov
committed
feat: HMR bootstrap and livesinc options
1 parent 70d5457 commit 8f09598

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Diff for: nativescript-angular/platform-common.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ if ((<any>global).___TS_UNUSED) {
5050
return InjectionToken;
5151
})();
5252
}
53+
54+
export interface HmrOptions {
55+
moduleTypeFactory?: () => Type<any> | NgModuleFactory<any>
56+
livesyncCallback: (bootstrapPlatfrom: () => void) => void;
57+
}
58+
5359
export interface AppOptions {
5460
bootInExistingPage?: boolean;
5561
cssFile?: string;
5662
startPageActionBarHidden?: boolean;
5763
createFrameOnBootstrap?: boolean;
64+
hmr?: HmrOptions;
5865
}
5966

6067
export type PlatformFactory = (extraProviders?: StaticProvider[]) => PlatformRef;
@@ -91,7 +98,9 @@ export class NativeScriptPlatformRef extends PlatformRef {
9198

9299
@profile
93100
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+
);
95104

96105
this.bootstrapApp();
97106

@@ -103,7 +112,9 @@ export class NativeScriptPlatformRef extends PlatformRef {
103112
moduleType: Type<M>,
104113
compilerOptions: CompilerOptions | CompilerOptions[] = []
105114
): 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);
107118

108119
this.bootstrapApp();
109120

@@ -113,7 +124,11 @@ export class NativeScriptPlatformRef extends PlatformRef {
113124
@profile
114125
private bootstrapApp() {
115126
(<any>global).__onLiveSyncCore = () => {
116-
this._livesync();
127+
if (this.appOptions.hmr) {
128+
this.appOptions.hmr.livesyncCallback(() => this._livesync());
129+
} else {
130+
this._livesync();
131+
}
117132
};
118133

119134
if (this.appOptions && typeof this.appOptions.cssFile === "string") {
@@ -224,7 +239,12 @@ export class NativeScriptPlatformRef extends PlatformRef {
224239
if (isLogEnabled()) {
225240
bootstrapLog("Angular livesync started.");
226241
}
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+
}
228248

229249
const autoCreateFrame = !!this.appOptions.createFrameOnBootstrap;
230250
let tempAppHostView: AppHostView;

0 commit comments

Comments
 (0)