React Executor - v0.0.29
    Preparing search index...

    Class SSRExecutorManager

    The executor manager that sends executor states to the client during server-side rendering.

    Hierarchy (View Summary)

    Index
    _executorPredicate: (executor: Executor) => boolean

    Selects executors whose state is sent to the client.

    _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 ID 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 created.

    _plugins: ExecutorPlugin[] = []

    Plugins that are applied to all executors.

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

    The pubsub that handles the manager subscriptions.

    _serializer: Serializer | JSON

    Stringifies executor keys and state snapshots before sending them to the client.

    keyIdGenerator: (key: unknown) => unknown

    Returns the ID of an executor key. Keys with the same ID refer to the same executor.

    nonce: string | undefined

    A nonce string to allow hydration scripts under a script-src Content-Security-Policy.

    • Aborts the pending tasks of all executors. The executor results are preserved as is.

      Parameters

      • Optionalreason: unknown

        The reason that rejects the aborted task promises.

      Returns void

    • Detaches an executor that isn't active from the manager.

      A pending task of the detached executor isn't aborted. To abort it, subscribe to the detached event.

      Parameters

      • key: unknown

        The unique executor key.

      Returns boolean

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

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

      Parameters

      • key: unknown

        The unique executor key.

      Returns Executor<any> | undefined

    • Resolves with the executor that has the key, and waits for the executor to be created if it doesn't exist yet.

      If the signal is aborted, the promise is rejected with the abort reason.

      Parameters

      • key: unknown

        The unique executor key.

      • options: { signal?: AbortSignal } = {}

        Options with the signal that aborts waiting.

        • Optionalsignal?: AbortSignal

          The signal that aborts the operation.

      Returns Promise<Executor<any>>

    • Returns an existing executor or creates a new one.

      If a plugin throws, the pending task of the new executor is aborted, the detached event is published, and the error is rethrown.

      Type Parameters

      • Value = any

      Parameters

      • key: unknown

        The unique executor key.

      • initialValue: undefined

        The initial value of a new executor: a value, a promise, or a task callback to execute. It isn't applied if plugins have already settled the executor or started a task.

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

        Plugins that are applied to a new executor.

      Returns Executor<Value>

    • Returns an existing executor or creates a new one.

      If a plugin throws, the pending task of the new executor is aborted, the detached event is published, and the error is rethrown.

      Type Parameters

      • Value = any

      Parameters

      • key: unknown

        The unique executor key.

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

        The initial value of a new executor: a value, a promise, or a task callback to execute. It isn't applied if plugins have already settled the executor or started a task.

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

        Plugins that are applied to a new executor.

      Returns Executor<Value>

    • Waits until no executors are pending, and resolves with true if the state of any executor has changed since this method was called, or false otherwise. Use it to re-render the app on the server until all data is loaded.

      The returned promise is rejected if executors are still pending after maxRetries attempts. This usually means that a plugin keeps re-executing tasks during SSR.

      Parameters

      • maxRetries: number = 10

        The maximum number of times to wait for executors that become pending again. Increase it if data is loaded in many sequential steps.

      Returns Promise<boolean>

    • Sets the initial state of an executor that hasn't been created yet. The state is applied when the executor is created with getOrCreate.

      Parameters

      • key: unknown

        The unique executor key.

      • initialState: ExecutorState

        The initial state of the executor.

      Returns boolean

      true if the initial state was set, or false if the executor already exists.

    • Returns a <script> tag that sends the client the states of executors that have changed since they were last sent, or an empty string if there are no such changes.

      Returns string

    • Returns the source of a script that sends the client the states of executors that have changed since they were last sent, or an empty string if there are no such changes.

      Returns string

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

      Parameters

      • listener: (event: ExecutorEvent) => void

        The listener to subscribe.

      Returns () => void

      The callback that unsubscribes the listener.