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

Commit aa4fc42

Browse files
steve8708PatrickJS
authored andcommitted
feat(universal): Allow for configuring if preboot complete() is called automatically (immediatelly) or manually (asynchronously) (#552)
* 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. * fix(universal): Resolve tsc error with createGlobalProxy return types
1 parent a01f34a commit aa4fc42

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-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
}

modules/universal/src/node/proxy-document.ts

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export function createGlobalProxy() {
136136
}
137137
});
138138

139+
return document;
139140
}
140141

141142

0 commit comments

Comments
 (0)