Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit e10b5ac

Browse files
committed
feat(universal): Allow for configuring if preboot complete() is called automatically (immediatelly) or manually (asynchronously)
This is useful if you need to do anything asynchronous (e.g. fetch data) before preboot complete() is called.
1 parent a01f34a commit e10b5ac

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

modules/universal/src/browser/universal-module.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class OpaqueToken {
4242
const SharedStylesHost: any = __platform_browser_private__.SharedStylesHost;
4343

4444
export const UNIVERSAL_CACHE = new OpaqueToken('UNIVERSAL_CACHE');
45+
export const AUTO_PREBOOT = new OpaqueToken('AUTO_PREBOOT');
4546

4647
@NgModule({
4748
imports: [
@@ -76,16 +77,23 @@ export const UNIVERSAL_CACHE = new OpaqueToken('UNIVERSAL_CACHE');
7677
},
7778
deps: []
7879
},
80+
{
81+
provide: AUTO_PREBOOT,
82+
useValue: true
83+
},
7984
{
8085
multi: true,
8186
provide: APP_BOOTSTRAP_LISTENER,
82-
useValue: () => {
83-
let _win: any = window;
84-
if (_win && prebootClient) {
85-
setTimeout(() => prebootClient().complete());
86-
}
87-
}
88-
}
87+
useFactory: (autoPreboot: boolean) => {
88+
return () => {
89+
let _win: any = window;
90+
if (_win && prebootClient && autoPreboot) {
91+
setTimeout(() => prebootClient().complete());
92+
}
93+
};
94+
},
95+
deps: [ AUTO_PREBOOT ],
96+
},
8997
]
9098
})
9199
export class UniversalModule {
@@ -101,10 +109,18 @@ export class UniversalModule {
101109
});
102110
}
103111
static withConfig(_config: any = {}): {ngModule: UniversalModule, providers: any[]} {
112+
const providers = [];
113+
114+
if (typeof _config.autoPreboot === 'boolean') {
115+
providers.push({
116+
provide: AUTO_PREBOOT,
117+
useValue: _config.autoPreboot,
118+
});
119+
}
120+
104121
return {
105122
ngModule: UniversalModule,
106-
providers: [
107-
]
123+
providers: providers,
108124
};
109125
}
110126
}

0 commit comments

Comments
 (0)