Skip to content

Commit fee8fc6

Browse files
author
vakrilov
committed
style: long-lines, jsdoc, typos
1 parent e6d09db commit fee8fc6

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

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

+35-10
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,33 @@ if ((<any>global).___TS_UNUSED) {
5151
})();
5252
}
5353

54+
// tslint:disable:max-line-length
55+
/**
56+
* Options to be passed when HMR is enabled
57+
*/
5458
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+
*/
5563
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;
5771
}
72+
// tslint:enable:max-line-length
73+
5874

5975
export interface AppOptions {
6076
bootInExistingPage?: boolean;
6177
cssFile?: string;
6278
startPageActionBarHidden?: boolean;
6379
createFrameOnBootstrap?: boolean;
64-
hmr?: HmrOptions;
80+
hmrOptions?: HmrOptions;
6581
}
6682

6783
export type PlatformFactory = (extraProviders?: StaticProvider[]) => PlatformRef;
@@ -98,9 +114,14 @@ export class NativeScriptPlatformRef extends PlatformRef {
98114

99115
@profile
100116
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+
};
104125

105126
this.bootstrapApp();
106127

@@ -112,10 +133,14 @@ export class NativeScriptPlatformRef extends PlatformRef {
112133
moduleType: Type<M>,
113134
compilerOptions: CompilerOptions | CompilerOptions[] = []
114135
): 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+
}
118141

142+
return this.platform.bootstrapModule(bootstrapType, compilerOptions);
143+
};
119144
this.bootstrapApp();
120145

121146
return null; // Make the compiler happy
@@ -124,8 +149,8 @@ export class NativeScriptPlatformRef extends PlatformRef {
124149
@profile
125150
private bootstrapApp() {
126151
(<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());
129154
} else {
130155
this._livesync();
131156
}

0 commit comments

Comments
 (0)