Skip to content

Instantly share code, notes, and snippets.

@fyodorio
Last active August 23, 2021 12:29
Show Gist options
  • Save fyodorio/21b7686161b4d34c12af57767e4ad53f to your computer and use it in GitHub Desktop.
Save fyodorio/21b7686161b4d34c12af57767e4ad53f to your computer and use it in GitHub Desktop.
Example of NgRx facade
@Injectable()
export class ConfigurationsFacade {
/**
* Combine pieces of state using createSelector,
* and expose them as observables through the facade.
*/
loaded$ = this.store.pipe(select(ConfigurationsSelectors.getConfigurationsLoaded));
failed$ = this.store.pipe(select(ConfigurationsSelectors.getConfigurationsLoadFailed));
allConfigurations$: Observable<Configuration[]> = this.store.pipe(select(ConfigurationsSelectors.getAllConfigurations));
selectedConfigurations$ = this.store.pipe(select(ConfigurationsSelectors.getSelected));
constructor(private store: Store) {}
/**
* Use the initialization action to perform one
* or more tasks in your Effects.
*/
loadConfigurations() {
this.store.dispatch(ConfigurationsActions.loadConfigurations());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment