Class SSRExecutorManager

The base implementation of the executor manager that supports client hydration after SSR.

Hierarchy (view full)

Constructors

Properties

_executorFilter: ((executor: Executor<any>) => boolean)

Filters executors that must be hydrated on the client with the state that was accumulated during SSR.

_executors: Map<unknown, ExecutorImpl<any>> = ...

The map from a key to an executor.

_hydratedVersions: WeakMap<Executor<any>, number> = ...

Map from an executor to a version of the state that was sent to the client for hydration.

_initialState: Map<unknown, ExecutorState<any>> = ...

The map from a key to an initial state that must be set to an executor before plugins are applied. Entries from this map are deleted after the executor is initialized.

_plugins: ExecutorPlugin[] = []

Plugins that are applied to all executors.

_pubSub: PubSub<ExecutorEvent<any>> = ...

The pubsub that handles the manager subscriptions.

_stateStringifier: {
    (value: any, replacer?: ((this: any, key: string, value: any) => any), space?: string | number): string;
    (value: any, replacer?: null | (string | number)[], space?: string | number): string;
}

Stringifies the state of the executor before sending it to the client.

Type declaration

    • (value, replacer?, space?): string
    • Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

      Parameters

      • value: any

        A JavaScript value, usually an object or array, to be converted.

      • Optionalreplacer: ((this: any, key: string, value: any) => any)

        A function that transforms the results.

          • (this, key, value): any
          • Parameters

            • this: any
            • key: string
            • value: any

            Returns any

      • Optionalspace: string | number

        Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

      Returns string

    • (value, replacer?, space?): string
    • Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

      Parameters

      • value: any

        A JavaScript value, usually an object or array, to be converted.

      • Optionalreplacer: null | (string | number)[]

        An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.

      • Optionalspace: string | number

        Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

      Returns string

keySerializer: ((key: unknown) => unknown)

Serializes keys of executors.

nonce: undefined | string

A nonce string to allow scripts for script-src Content-Security-Policy.

Methods

  • Instantly aborts all pending executors and preserves their available results as is.

    Parameters

    • Optionalreason: unknown

      The abort reason that is used for rejection of the pending task promises.

    Returns void

  • Deletes the non-active executor from the manager.

    If the detached executor is pending then it is not aborted. Subscribe to the detach event on either manager or an executor and abort it manually.

    Parameters

    • key: unknown

      The key of the executor to delete.

    Returns boolean

    true if the executor was detached, or false if there's no such executor, or the executor is active.

  • Returns an executor by its key, or undefined if there's no such executor.

    Parameters

    • key: unknown

      The unique executor key.

    Returns undefined | Executor<any>

  • Returns an existing executor or creates a new one.

    Type Parameters

    • Value = any

    Parameters

    • key: unknown

      The unique executor key.

    • initialValue: undefined

      The initial executor value.

    • Optionalplugins: (undefined | null | ExecutorPlugin<Value>)[]

      The array of plugins that are applied to the newly created executor.

    Returns Executor<Value>

  • Returns an existing executor or creates a new one.

    Type Parameters

    • Value = any

    Parameters

    • key: unknown

      The unique executor key.

    • OptionalinitialValue: Value | ExecutorTask<Value> | PromiseLike<Value>

      The initial executor value.

    • Optionalplugins: (undefined | null | ExecutorPlugin<NoInfer<Value>>)[]

      The array of plugins that are applied to the newly created executor.

    Returns Executor<Value>

  • Resolves with true if there were pending executors and their state has changed after they became non-pending. Otherwise, resolves with false.

    Returns Promise<boolean>

  • Injects the initial state for the executor that is created in the future.

    Parameters

    Returns boolean

    true if the executor was hydrated, or false if the executor already exists and cannot be hydrated.

  • Returns an inline <script> tag with source that hydrates the client with the state accumulated during SSR, or an empty string if there are no state changes since the last time nextHydrationScript was called.

    Returns string

  • Returns a script source that hydrates the client with the state accumulated during SSR, or an empty string if there are no state changes since the last time nextHydrationScript was called.

    Returns string

  • Subscribes a listener to the events published by all executors that are created by this manager.

    Parameters

    • listener: ((event: ExecutorEvent<any>) => void)

      The listener to subscribe.

    Returns (() => void)

    The callback that unsubscribes the listener.

      • (): void
      • Returns void