Skip to content

Instantly share code, notes, and snippets.

@matheo
Created February 15, 2019 05:11
Show Gist options
  • Save matheo/731603757d4781e31605c8d6a61684f3 to your computer and use it in GitHub Desktop.
Save matheo/731603757d4781e31605c8d6a61684f3 to your computer and use it in GitHub Desktop.
Angular APP_INITIALIZER with NgRx Effects
/**
* App Initializer with Effects
*/
export function initApplication(store: Store<AppState>) {
return () =>
new Promise(resolve => {
const loaded$ = new Subject();
store.dispatch(new LoadSystem());
store
.select((state:AppState) => state.isLoaded)
.pipe(takeUntil(loaded$))
.subscribe(loaded => {
if (loaded) {
loaded$.next();
resolve();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment