Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active February 18, 2020 02:48
Show Gist options
  • Save alexytiger/40c760d035b05025499c74bd97b09acc to your computer and use it in GitHub Desktop.
Save alexytiger/40c760d035b05025499c74bd97b09acc to your computer and use it in GitHub Desktop.
e-book
export class ViewPurchaseContractComponent implements OnInit, OnDestroy {
selectedPurchaseContract$: Observable<PurchaseContractModel>;
image$: Observable<Blob>;
constructor(
private store$: Store<fromStore.AppState>,
) { }
ngOnInit() {
this.selectedPurchaseContract$ = this.store$.pipe(
select(fromStore.getSelectedProductWidget),
filter(product => !!product),
tap(product =>
this.store$.dispatch(PurchaseContractActions.
loadPurchaseContract({ address: product.contractAddress }))),
// we switch from one observable to another
switchMap(() =>
this.store$.select(fromStore.getSelectedPurchaseContract)),
filter(contract => !!contract),
);
this.image$ = this.store$.pipe(
select(fromStore.getSelectedPurchaseContract),
filter(contract => !!contract),
tap(contract =>
this.store$.dispatch(IpfsImageActions.
downloadImage({ ipfsHash: contract.ipfsHash }))
),
// we switch from one observable to another
switchMap(() => this.store$.select(fromStore.getImageBlob)),
filter(image => !!image)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment