Derived Reactive Observable State with Slice

Updated Version

There’s an updated version of this article here:

Scenario

Our application calculates an Observable<Result>. We store this result in our Firefly Semantics Slice Object Store.

We want to know when the result is ready, such that we can enable the save button.

Approach

First we will create our object store with an initial value of null for RESULT :

export const OSK: OStoreStart = {
RESULT: { value: null }
};
export interface OSKI {
RESULT: ObsValueReset;
}
const OS: OStore<OSKI> = new OStore<OSKI>(OSK);

Then we will observe this value:

const isResultReady$: Observable<boolean> = OS.S.RESULT.obs.pipe(
map(r => { return !!r;})
);

Demo

When we update the value of RESULT to a non null value, true is logged. When RESULT is set to null false is logged:

--

--

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