gameforge - v0.1.12
    Preparing search index...

    Class Runner<T, ARG>

    A Runner is a highly performant and simple alternative to signals. Best used in situations where events are dispatched to many objects at high frequency (say every frame!)

    Like a signal:

    import { Runner } from '@pixi/runner';

    const myObject = {
    loaded: new Runner('loaded'),
    };

    const listener = {
    loaded: function() {
    // Do something when loaded
    }
    };

    myObject.loaded.add(listener);

    myObject.loaded.emit();

    Or for handling calling the same function on many items:

    import { Runner } from '@pixi/runner';

    const myGame = {
    update: new Runner('update'),
    };

    const gameObject = {
    update: function(time) {
    // Update my gamey state
    },
    };

    myGame.update.add(gameObject);

    myGame.update.emit(time);

    Type safety:


    import { Runner } from '@pixi/runner';

    let runner: Runner<'update', [number]>;

    // This won't work because the function name 'update' is expected
    runner = new Runner('destroy');

    // This is fine
    runner = new Runner('update');

    // This won't work because the number is expected
    runner.emit("10");

    // This is fine
    runner.emit(10);

    // This won't work because provided object does not contain 'update' key
    runner.add({
    destroy: function() {
    // Destroy the game
    },
    });

    // This is fine
    runner.add({
    update: function(time) {
    // Update my gamey state
    },
    destroy: function() {
    // Destroy the game
    },
    });

    PIXI

    Type Parameters

    • T = any

      The event type.

    • ARG extends unknown[] = any[]

      The argument types for the event handler functions.

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    • Type Parameters

      • T = any
      • ARG extends unknown[] = any[]

      Parameters

      • name: T

        The function name that will be executed on the listeners added to this Runner.

      Returns Runner<T, ARG>

    Properties

    items: any[]

    Accessors

    • get empty(): boolean

      true if there are no this Runner contains no listeners

      Returns boolean

    • get name(): T

      The name of the runner.

      Returns T

    Methods

    • Add a listener to the Runner

      Runners do not need to have scope or functions passed to them. All that is required is to pass the listening object and ensure that it has contains a function that has the same name as the name provided to the Runner when it was created.

      E.g. A listener passed to this Runner will require a 'complete' function.

      import { Runner } from '@pixi/runner';

      const complete = new Runner('complete');

      The scope used will be the object itself.

      Parameters

      Returns this

    • Check to see if the listener is already in the Runner

      Parameters

      Returns boolean

    • Remove all references, don't use after this.

      Returns void

    • Dispatch/Broadcast Runner to all listeners added to the queue.

      Parameters

      • Optionala0: ARG[0]
      • Optionala1: ARG[1]
      • Optionala2: ARG[2]
      • Optionala3: ARG[3]
      • Optionala4: ARG[4]
      • Optionala5: ARG[5]
      • Optionala6: ARG[6]
      • Optionala7: ARG[7]

      Returns this

    • Remove a single listener from the dispatch queue.

      Parameters

      Returns this

    • Remove all listeners from the Runner

      Returns this