Effect CommunityEC
Effect Community2y ago
7 replies
Gibbs

Conditional Provision of DevTools Layer in Configuration

Is this the correct way of providing the DevTools layer conditionally ?
const DevToolsLayer = Layer.effectDiscard(
  Effect.gen(function* (_) {
    const enableDevTools = yield* _(
      Config.boolean('ENABLE_DEV_TOOLS'),
      Config.withDefault(false),
    );
    if (enableDevTools) {
      yield* _(DevTools.layer(), Layer.build);
    }
  }),
);

const LiveLayer = Layer.merge(AppLive, DevToolsLayer)

const program = Effect.log('Hello').pipe(Effect.provide(LiveLayer))


I feel like having to call Layer.build is bad but I don't know why..
Was this page helpful?