Issue with Layer Dependencies in AtomHttpClient Setup

Hello,

When creating a AtomHttpClient I'm struggling to provide a proper layer to fix alle dependencies.

const MasonHttpClient = FetchHttpClient.layer.pipe(
  Layer.provide(
    Layer.effect(
      FetchHttpClient.Fetch,
      Effect.gen(function* () {
        // Custom fetch command for desktop apps
        const platform = yield* PlatformService;
        return platform.platform === "desktop"
          ? (platform.fetch as typeof fetch)
          : fetch;
      })
    ).pipe(Layer.provide(appLayer)) // This is the problem area it seems
  )
);

class MasonAtomClient extends AtomHttpApi.Tag<MasonAtomClient>()(
  "MasonAtomClient",
  {
    api: MasonApi,
    baseUrl: "http://localhost:8002",
    httpClient: MasonHttpClient,
  }
) {}


appLayer comes from this function

export let appLayer: Layer.Layer<LedgerService | PlatformService, never, never>;

export function renderMasonInterface({ platform }: { platform: Platform }) {
  appLayer = LedgerService.Default.pipe(
    Layer.provideMerge(PlatformService.live(platform))
  );

  // Set react root


The problem is that using appLayer like this gives a lexical error when compiling modules. And I am struggling to think of any real workaround to this problem that would still preserve the ergenomics of effect. I.E. no lazy loaded services.

Anyone with a good suggestion?
Was this page helpful?