Client Layer
Client.layerSocket(...) turns a Client protocol into a live Effect layer backed by a WebSocket.
Use it in browser runtimes that connect to a Liminal actor through an HTTP upgrade route.
Define the layer
Provide the client definition, reducers, the socket endpoint, and the platform WebSocket constructor.
import { BrowserSocket } from "@effect/platform-browser"
import { Layer } from "effect"
import { Client } from "liminal"
import { TicTacToeClient } from "./TicTacToeClient.ts"
import * as reducers from "./reducers.ts"
const TicTacToeClientLive = Client.layerSocket({
client: TicTacToeClient,
url: "/play",
replay: { mode: "startup" },
reducers,
}).pipe(Layer.provide(BrowserSocket.layerWebSocketConstructor))layerSocket accepts:
client: theClientdefinitionreducers: a reducer table keyed by event tagurl: the WebSocket endpoint path, defaulting to"/"protocols: one or more extra WebSocket sub-protocolsreplay: optional event replay configurationonConnect: optional effect that runs with the hydrated state once audition succeeds
Replay semantics are covered in Events.
layerSocket requires a Socket.WebSocketConstructor in the environment. In browsers, that usually comes from
BrowserSocket.layerWebSocketConstructor in @effect/platform-browser.
Use the live client
After providing the layer, calls use Client.fn(...), event streams use Client.events, and hydrated state uses
Client.state.
Read Client Calls and Events for those APIs.