Skip to content

Instantly share code, notes, and snippets.

@Gbuomprisco
Created May 26, 2019 12:27
Show Gist options
  • Save Gbuomprisco/c7dbd539887fe0a391f6576f82a0d7e2 to your computer and use it in GitHub Desktop.
Save Gbuomprisco/c7dbd539887fe0a391f6576f82a0d7e2 to your computer and use it in GitHub Desktop.
@Injectable()
export class PricesFacadeServiceImpl implements PricesFacadeService {
subscribedAssets$: Observable<string[]> = this.store.select(
selectSubscribedAssets
);
constructor(private store: Store<EntityState<PriceState>>) {}
public createPriceSubscription(assetId: string) {
this.addInitialPrice(assetId);
this.createSubscription(assetId);
}
public getPriceForAsset(assetId: string): Observable<string> {
return this.store.select(selectPriceForAsset(assetId));
}
private addInitialPrice(assetId: string) {
this.store.dispatch(addPrice({ payload: { [assetId]: '' } }));
}
private createSubscription(assetId: string) {
this.store.dispatch(createPriceSubscription({ payload: assetId }));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment