Unsubscribing From Firefly Semantics Slice Object Store Observables in Angular

Scenario

We access our CSV data via a Slice Object Store observable like this:

this.s.os.S.CSV_DATA.obs.subscribe(data=>console.log(data))

We want to automatically unsubscribe when the component is destroyed.

Approach

Use the library @ngneat/until-destroy:

npm i @ngneat/until-destroy

Decorate the component with @UntilDestroy() :

@UntilDestroy()
@Component({
...
})

And pipe through untilDestroy :

this.s.os.S.CSV_DATA.obs.pipe(untilDestroyed(this)).subscribe(...)

The Subscription instance will now be automatically unsubscribed.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation