Last active
February 18, 2020 02:48
-
-
Save alexytiger/40c760d035b05025499c74bd97b09acc to your computer and use it in GitHub Desktop.
e-book
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
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