Skip to content

Interface: ViewSession<TActor>

API / @xmachines/play-view / index / ViewSession

Defined in: packages/play-view/src/view-session.ts:88

The view session of one provider.

Type Parameters

Type ParameterDefault typeDescription
TActor extends ViewActorViewActorThe type of the actor of the provider.

Methods

dispose()

dispose(): void;

Defined in: packages/play-view/src/view-session.ts:142

Disconnects the session and drops its store. A later call does nothing.

Returns

void


failView()

failView(error, attempt?): void;

Defined in: packages/play-view/src/view-session.ts:140

Records a failure of the root of the view that json-render reported, as a failure of the snapshot: the new snapshot holds the failure and no store, and a connected session reports it through ViewSessionOptions.onFailure. The failure stands until a new attempt: a new view, a new actor, a new controlled store, or a retry. A connection keeps it, also a second one: it makes a new attempt only when the view moved or a controlled store waits for its /context.

The root boundary of json-render stays failed while its subtree stays mounted. The next attempt therefore gets a new generation, and a provider mounts a new subtree for it, with the same state. A root that fails again there reports again.

The call does nothing for a snapshot that holds no view or a failure already, and for an attempt that is not the current snapshot: a report that arrives after the next snapshot belongs to an attempt that is gone.

Parameters

ParameterTypeDescription
errorunknownThe failure of the root.
attempt?ViewSessionSnapshot<TActor>The snapshot that the failed render showed. Leave it out where the report arrives in the render of the current snapshot, and where the root boundary of json-render stays failed while its subtree stays mounted: a report that fails a newer snapshot shows the fallback, and the next attempt recovers from it, but a report that the session drops leaves an empty view. The four framework providers leave it out for that reason.

Returns

void


getSnapshot()

getSnapshot(): ViewSessionSnapshot<TActor>;

Defined in: packages/play-view/src/view-session.ts:98

The current snapshot. The first call resolves one time, without a write of the controlled store, and a later call returns the snapshot of the last resolution. A render may call it.

In a session that no listener connects, setInputs() and retry() drop the snapshot, so the next call resolves again, also without a write. A provider must not keep the first snapshot as the final one.

Returns

ViewSessionSnapshot<TActor>


retry()

retry(): void;

Defined in: packages/play-view/src/view-session.ts:115

Resolves the view that the actor holds NOW, for a retry of the host.

Returns

void


setInputs()

setInputs(actor, store): void;

Defined in: packages/play-view/src/view-session.ts:113

Hands over the actor and the controlled store of the host. A change of either one resolves again, and a new actor also drops the store of the old one. Call it outside a render.

Parameters

ParameterType
actorTActor
storeStateStore | undefined

Returns

void


subscribe()

subscribe(listener): () => void;

Defined in: packages/play-view/src/view-session.ts:107

Adds a listener of new snapshots. The first listener connects the session: it watches the view of the actor, and it resolves again, which writes /context into a controlled store. The last release disconnects it and keeps the store, so a framework that subscribes again, such as React in <StrictMode>, finds its state.

Parameters

ParameterType
listener() => void

Returns

The release of the listener.

() => void