Help Needed with Caching Dependencies in Effect Layers System

Hi there I'm a bit lost on caching a dependency using the effect layers systems can anybody give me a hand with this?

I have a Store which programs use as follows:

const process = (payload: any) => Effect.gen(function* (_) {
  const store = yield* _(Store)
  store.get(payload.id)
})


but I provide the dependency based on a boolean, like so:

const useStoreA = (payload: any) => Effect.provide(process(payload), StoreA)
const useStoreB = (payload: any) => Effect.provide(process(payload), StoreB)

const caller = (payload: any) => Effect.gen(function* (_) {
  const storeToUse = payload.useA ? useStoreA : useStoreB

  yield* _(storeToUse(payload))
})
Was this page helpful?