Function Implant

  • The Implant decorator, when applied to classes extending the abstract Effect base class, StateHandler.implants the decorated class under the locate in the global sgrud.state.effects namespace to be used within StateHandler.dispatched Store.Actions.

    Type Parameters

    Parameters

    • locate: K

      The locate to address the Effect by.

    Returns ((constructor) => void)

    A class constructor decorator.

      • (constructor): void
      • Parameters

        • constructor: T

        Returns void

    Example

    An importScripts Effect:

    import { Effect, Implant, type StateWorker, type Store } from '@sgrud/state';

    declare global {
    namespace sgrud.state.effects {
    function importScripts(...urls: (string | URL)[]): Promise<void>;
    }
    }

    ⁠@Implant('importScripts')
    export class ImportScriptsEffect extends Effect {

    public override function(
    this: StateWorker
    ): Store.Effects['importScripts'] {
    return async(...urls) => {
    return importScripts(...urls);
    };
    }

    }

    See

Generated using TypeDoc