clientLayer function

Module @runic-artifex/views-effect in @runic-artifex/views-effect 0.23.0

function clientLayer<I, C extends ViewClient>(service: Context.Key<I, C>, source: ViewConnector<C> | (() => PromiseLike<C>)): Layer.Layer<I, ViewError>;

A layer that provides a connected client as service. It connects when the layer is built, fails with a ViewError when the client cannot connect, and disposes the client when the layer's scope closes, for example when a ManagedRuntime built from it is disposed.

class Editor extends Context.Service<Editor, EditorClient>()("app/Editor") {}
const EditorLive = clientLayer(Editor, connectEditor);

const save = Effect.gen(function* () {
  const editor = yield* Editor;
  yield* command(() => editor.save());
}).pipe(Effect.provide(EditorLive));