website icon indicating copy to clipboard operation
website copied to clipboard

Add an example to https://www.effect.website/docs/faq#configuring-layers

Open steida opened this issue 2 years ago • 0 comments

For example, that's what I have in Evolu. Note EvoluLive(schema) vs ReactLive. The Layer is like a constructor without a new, if I understand it properly. Hence PascalCase. Am I correct?

const Live = <From, To extends Schema>(
  schema: S.Schema<From, To>,
  config?: Partial<Config>
): Layer.Layer<never, never, React<Schema>> =>
  ConfigLive(config).pipe(
    Layer.provide(EvoluLive(schema)),
    Layer.provide(ReactLive)
  );

export const create = <From, To extends Schema>(
  schema: S.Schema<From, To>,
  config?: Partial<Config>
): React<To>["hooks"] =>
  React.pipe(
    Effect.map((react) => react.hooks as React<To>["hooks"]),
    Effect.provideLayer(Live<From, To>(schema, config)),
    Effect.runSync
  );

steida avatar Jul 19 '23 09:07 steida