Created
February 15, 2019 05:11
-
-
Save matheo/731603757d4781e31605c8d6a61684f3 to your computer and use it in GitHub Desktop.
Angular APP_INITIALIZER with NgRx Effects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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