Skip to content
Liminal

Lifecycle

hydrate runs when a client socket is newly upgraded into an actor.

Use it to return the connecting client's initial state and notify already-connected clients.

Hydrate initial state

 
export const  = .(function* () {
  const {  } = yield* 
  if (. === 1) {
    return {
      : true,
      : "X" as ,
    }
  }
 
  yield* ..("GameStarted", {})
  return {
    : false,
    : "O" as ,
  }
}).(.)

hydrate is the snapshot for a reconnectable client. Tic-tac-toe returns awaitingPartner: true to the first socket, then sends GameStarted to the existing player and returns ready state to the second player.

onDisconnect runs when a socket closes or disconnects and is supplied to ActorRuntime.make(...).

Read Snapshot and Delta Events for the state pattern and Client State for the hydration and reduction loop.