Sanity Library Reference Docs
    Preparing search index...

    Interface MessageBusHost<TTopics>

    The host's connection to the bus.

    State reaches an application only through MessageBusClient.emit. There is no broadcast: sending the same value to everyone is a loop over connections, and giving a new connection the current values is done when it appears there, as an SSE server writes a snapshot to each new client.

    interface MessageBusHost<TTopics = MessageBusTopics> {
        appId: string;
        connections: Observable<MessageBusClient>;
        disconnect(): void;
        emit<K extends string | number | symbol>(
            type: K,
            ...rest: PayloadOf<K, TTopics> extends void
                ? [payload?: void, options?: MessageBusEmitOptions]
                : [payload: PayloadOf<K, TTopics>, options?: MessageBusEmitOptions],
        ): MessageBusEmitResult<ReplyOf<K, TTopics>>;
        query<K extends string | number | symbol>(
            type: K,
            options?: MessageBusQueryOptions,
        ): Promise<ValueOf<K, TTopics>>;
        subscribe<K extends string | number | symbol>(
            type: K,
            handler: (
                message: MessageBusMessage<
                    PayloadOf<K, TTopics>,
                    ReplyOf<K, TTopics>,
                    K,
                >,
            ) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends string | number | symbol>(
            type: K,
            handler: (value: ValueOf<K, TTopics>) => void,
            options?: MessageBusAbortOptions,
        ): void;
        subscribe<K extends string | number | symbol>(
            type: K,
        ): MessageBusStateSource<ValueOf<K, TTopics>>;
        subscribe<K extends string | number | symbol>(
            type: K,
        ): Observable<PayloadOf<K, TTopics>>;
    }

    Type Parameters

    • TTopics = MessageBusTopics

    Hierarchy (View Summary)

    Index

    Properties

    appId: string

    The application this connection belongs to.

    connections: Observable<MessageBusClient>

    Every open connection other than this one first, then each new one as it joins. The same MessageBusClient object is handed out for a connection across subscriptions, so it can be kept in a Set. A connection stays listed until it calls disconnect(); the SDK does that when the owning SanityInstance is disposed.

    Methods