index.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * A Runner is a highly performant and simple alternative to signals. Best used in situations
  3. * where events are dispatched to many objects at high frequency (say every frame!)
  4. *
  5. *
  6. * like a signal..
  7. * ```
  8. * import { Runner } from '@pixi/runner';
  9. *
  10. * const myObject = {
  11. * loaded: new Runner('loaded')
  12. * }
  13. *
  14. * const listener = {
  15. * loaded: function(){
  16. * // thin
  17. * }
  18. * }
  19. *
  20. * myObject.loaded.add(listener);
  21. *
  22. * myObject.loaded.emit();
  23. * ```
  24. *
  25. * Or for handling calling the same function on many items
  26. * ```
  27. * import { Runner } from '@pixi/runner';
  28. *
  29. * const myGame = {
  30. * update: new Runner('update')
  31. * }
  32. *
  33. * const gameObject = {
  34. * update: function(time){
  35. * // update my gamey state
  36. * }
  37. * }
  38. *
  39. * myGame.update.add(gameObject);
  40. *
  41. * myGame.update.emit(time);
  42. * ```
  43. * @memberof PIXI
  44. */
  45. export declare class Runner {
  46. items: any[];
  47. private _name;
  48. private _aliasCount;
  49. /**
  50. * @param name - The function name that will be executed on the listeners added to this Runner.
  51. */
  52. constructor(name: string);
  53. /**
  54. * Dispatch/Broadcast Runner to all listeners added to the queue.
  55. * @param {...any} params - (optional) parameters to pass to each listener
  56. */
  57. emit(a0?: unknown, a1?: unknown, a2?: unknown, a3?: unknown, a4?: unknown, a5?: unknown, a6?: unknown, a7?: unknown): this;
  58. private ensureNonAliasedItems;
  59. /**
  60. * Add a listener to the Runner
  61. *
  62. * Runners do not need to have scope or functions passed to them.
  63. * All that is required is to pass the listening object and ensure that it has contains a function that has the same name
  64. * as the name provided to the Runner when it was created.
  65. *
  66. * Eg A listener passed to this Runner will require a 'complete' function.
  67. *
  68. * ```
  69. * import { Runner } from '@pixi/runner';
  70. *
  71. * const complete = new Runner('complete');
  72. * ```
  73. *
  74. * The scope used will be the object itself.
  75. * @param {any} item - The object that will be listening.
  76. */
  77. add(item: unknown): this;
  78. /**
  79. * Remove a single listener from the dispatch queue.
  80. * @param {any} item - The listener that you would like to remove.
  81. */
  82. remove(item: unknown): this;
  83. /**
  84. * Check to see if the listener is already in the Runner
  85. * @param {any} item - The listener that you would like to check.
  86. */
  87. contains(item: unknown): boolean;
  88. /** Remove all listeners from the Runner */
  89. removeAll(): this;
  90. /** Remove all references, don't use after this. */
  91. destroy(): void;
  92. /**
  93. * `true` if there are no this Runner contains no listeners
  94. * @readonly
  95. */
  96. get empty(): boolean;
  97. /**
  98. * The name of the runner.
  99. * @readonly
  100. */
  101. get name(): string;
  102. }
  103. export { }