Skip to content

feat: HMR bootstrap and livesync options #1531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 9, 2018
Merged

feat: HMR bootstrap and livesync options #1531

merged 5 commits into from
Oct 9, 2018

Conversation

vakrilov
Copy link
Contributor

@vakrilov vakrilov commented Sep 25, 2018

Pass hmr specific options on application bootstrap. The hmr options are:

  • moduleTypeFactory?: () => Type<any> | NgModuleFactory<any>; A module factory for re-instantiating the bootstrap module or module-factory on livesync.
  • livesyncCallback: (bootstrapPlatfrom: () => void) => void; A livesync callback that will be called instead of the original livesync. It gives the hmr a hook to apply the module replacement. The callback also accepts bootstrapPlatfrom function which triggers bootstrap of the angular app with the existing platform using the moduleTypeFactory to get module/module-factory to be used.

@ghost ghost assigned vakrilov Sep 25, 2018
@ghost ghost added the in progress label Sep 25, 2018
@vakrilov vakrilov changed the title [Do not merge]feat: HMR bootstrap and livesync options [do not merge] feat: HMR bootstrap and livesync options Sep 25, 2018
@vakrilov vakrilov requested a review from sis0k0 October 1, 2018 08:12
@@ -224,7 +239,12 @@ export class NativeScriptPlatformRef extends PlatformRef {
if (isLogEnabled()) {
bootstrapLog("Angular livesync started.");
}
onBeforeLivesync.next(lastBootstrappedModule ? lastBootstrappedModule.get() : null);

const lastModuleRef = lastBootstrappedModule ? lastBootstrappedModule.get() : null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing semicolon

@vakrilov vakrilov changed the title [do not merge] feat: HMR bootstrap and livesync options feat: HMR bootstrap and livesync options Oct 8, 2018

export interface HmrOptions {
moduleTypeFactory?: () => Type<any> | NgModuleFactory<any>;
livesyncCallback: (bootstrapPlatfrom: () => void) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bootstrapPlatfrom -> bootstrapPlatform

export interface AppOptions {
bootInExistingPage?: boolean;
cssFile?: string;
startPageActionBarHidden?: boolean;
createFrameOnBootstrap?: boolean;
hmr?: HmrOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

hmr -> hmrOptions

I thought hmr was a boolean at first.

@@ -103,7 +112,9 @@ export class NativeScriptPlatformRef extends PlatformRef {
moduleType: Type<M>,
compilerOptions: CompilerOptions | CompilerOptions[] = []
): Promise<NgModuleRef<M>> {
this._bootstrapper = () => this.platform.bootstrapModule(moduleType, compilerOptions);
this._bootstrapper = () => this.platform.bootstrapModule(
this.appOptions.hmr ? <Type<M>>this.appOptions.hmr.moduleTypeFactory() : moduleType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That:

this.appOptions.hmr ? <Type ...

can be moved to a variable for readability.

onBeforeLivesync.next(lastBootstrappedModule ? lastBootstrappedModule.get() : null);

const lastModuleRef = lastBootstrappedModule ? lastBootstrappedModule.get() : null;
onBeforeLivesync.next(lastModuleRef);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to emit if there's no lastBootstrappedModule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be no lastBootstrappedModule if there was an error in the initial bootstrap and lastBootstrappedModule.get() will return null if the angular app was manually killed and collected (don't think it is a common practice in NS apps, but still ...). In either case I think the onBeforeLivesync should emit to be in balance with the onAfterLivesync.

@sis0k0 sis0k0 merged commit 1e92c7b into master Oct 9, 2018
@ghost ghost removed the in progress label Oct 9, 2018
@sis0k0 sis0k0 deleted the hmr-bootstrap branch October 9, 2018 12:06
NathanWalker pushed a commit to NathanWalker/nativescript-angular that referenced this pull request Oct 10, 2018
Pass `hmr` specific options on application bootstrap. The hmr options are:
- `moduleTypeFactory?: () => Type<any> | NgModuleFactory<any>;` A module factory for re-instantiating the bootstrap module or module-factory on livesync. 
- `livesyncCallback: (bootstrapPlatfrom: () => void) => void;` A `livesync` callback that will be called instead of the original livesync. It gives the `hmr` a hook to apply the module replacement. The callback also accepts `bootstrapPlatfrom` function which triggers bootstrap of the angular app with the existing platform using the `moduleTypeFactory` to get module/module-factory to be used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants