• Create a state-synchronized event stream that combines initial state with events

    Type Parameters

    • T = any

    Parameters

    • eventType: string

      The event type for updates

    • stateApi: string | (() => Promise<T>)

      API endpoint or function to fetch current state

    Returns {
        get state(): undefined | T;
        getState(): Promise<T>;
        subscribe(callback): (() => void);
        refresh(): Promise<T>;
    }

    Object with subscribe method and current state getter

    • get state(): undefined | T

      Get current state synchronously (may be undefined if not loaded)

    • getState:function
      • Get current state asynchronously (waits for initial load)

        Returns Promise<T>

    • subscribe:function
      • Subscribe to state changes (includes initial state)

        Parameters

        • callback: ((state) => void)
            • (state): void
            • Parameters

              • state: T

              Returns void

        Returns (() => void)

          • (): void
          • Returns void

    • refresh:function
      • Refresh state from API

        Returns Promise<T>