Sanity Library Reference Docs
    Preparing search index...

    Interface MessageBus

    Sends events and reads typed state and event topics.

    State topics are written by the host to each connection separately through MessageBusClient.emit; a connection only ever reads its own values.

    interface MessageBus {
        emit<K extends EventTopic>(
            type: K,
            ...rest: PayloadOf<K> extends void
                ? [payload?: void, options?: MessageBusEmitOptions]
                : [payload: PayloadOf<K>, options?: MessageBusEmitOptions],
        ): MessageBusEmitResult<ReplyOf<K>>;
        query<K extends StateTopic>(
            type: K,
            options?: MessageBusQueryOptions,
        ): Promise<ValueOf<K>>;
        subscribe<K extends EventTopic>(
            type: K,
            handler: (message: MessageBusMessage<PayloadOf<K>, ReplyOf<K>>) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends StateTopic>(
            type: K,
            handler: (value: ValueOf<K>) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends StateTopic>(type: K): MessageBusStateSource<ValueOf<K>>;
        subscribe<K extends EventTopic>(type: K): Observable<PayloadOf<K>>;
    }

    Hierarchy (View Summary)

    Index

    Methods