MockView interface

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

interface MockView

No documentation.

Properties

route

readonly route: string;

The route, such as counter or content1.

state

readonly state: MockState;

The current wire state.

revision

readonly revision: number;

The revision of the current state.

interactionHandlers

readonly interactionHandlers: readonly string[];

Interaction names that an open presentation currently handles.

requestHandlers

readonly requestHandlers: readonly string[];

View request names (view-requests/1) that an open presentation of this route on the connection registered.

epoch

readonly epoch: number;

The route's presentation epoch (presentation-epoch/1): the revision of its first state, then of each renewal. On a connection that uses the feature, open and snapshot replies and state pushes carry it, and a command that carries another epoch answers superseded without running.

Methods

update

update(patch: MockState | ((state: MockState) => MockState)): void;

Merges a patch and publishes it like a producer: a frame with a set change for each member whose value changed, at the window's next revision.

push

push(message: Readonly<Record<string, unknown>>): void;

Pushes a raw message to the client, such as a stale or malformed frame. route defaults to this route.

pushFailure

pushFailure(failure: {
    readonly kind?: BridgeErrorKind;
    readonly message: string;
    readonly detail?: BridgeFailureDetail;
}): void;

Pushes a failure: the producer cannot publish this route for now, so the client keeps its last state and reports the error.

collection

collection(field: string): MockCollection;

Edits a field declared in collections.

query

query(member: string): MockQueryCollection;

A query collection declared in queries.

batch

batch(edit: () => void): void;

Publishes the collection edits and updates made by edit as one frame.

failNext

failNext(match: {
    readonly kind: string;
    readonly member?: string;
}, failure: MockFailure, times?: number): void;

Answers the next times requests of kind (and member) of this route with failure.

operations

operations(member?: string): readonly MockOperation[];

Operations started on this View, oldest first, optionally of one command member.

interact

interact(name: string, input: unknown, options?: MockInteractionOptions): Promise<MockInteractionReply>;

Pushes an interaction request to the presentation that handles it, as a producer does.

raise

raise(name: string, input: unknown): number;

Raises a view request (view-requests/1), as a ViewModel's ViewRequest.Raise does: pushes view-request with the route's current revision and input (the wire value) to every presentation of this route on the connection that registered name, and returns how many it pushed to. 0 means that no presentation handles it; the request is not kept for a later registration. The mock runs no command scope or delivery rule: every registered presentation of the route receives it.

renew

renew(): void;

Begins a new epoch, as RunicPresentation.Renew(viewModel) does: the next publication is a state push at a new revision with the new epoch, also when no member changed. Called from a command handler, it is published with the command's changes; inside batch, when the batch ends; otherwise at once.

waitPresented

waitPresented(timeout?: number): Promise<boolean>;

Asks the page to report that it painted this route (presented/1), as RunicPresentation.WaitForPresentedAsync does: pushes present with the route's revision to a connection that uses the feature and has an open presentation of the route (or opens one while the wait is pending), and resolves true when the page reports presented at that revision or later, false after timeout milliseconds (default 5000; virtual time with manual scheduling).