Creating Proxies to Slice Object Store Observables in an Angular Environment | Task

Ole Ersoy
May - 11  -  1 min

Scenario

We model IS_AUTHENTICATED in our Firefly Semantics Slice Object Store ( OStore ).

const START: OStoreStart = {
  IS_AUTHENTICATED: { value: false }
};
interface ISTART {
  IS_AUTHENTICATED: ObsValueReset;
}
let OS: OStore<ISTART> = new OStore(START);

And we can access the corresponding Observable like this:

OS.S.IS_AUTHENTICATED.obs

But we would rather access it like this:

public isAuthenticated$:Observable<boolean>

Approach

Note that in order to ensure that the value is boolean typed we map it with the expression v=>!!v.

We also need to use Angulars non null assertion operator to tell Typescripts lint checker that the obs property is initialized.

public isAuthenticated$:Observable<boolean> = this.OS.S.IS_AUTHENTICATED.obs!.pipe(map(v=>!!v))

Demo