pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
1 lines • 5.69 kB
Source Map (JSON)
{"version":3,"file":"TickerListener.mjs","sources":["../../src/ticker/TickerListener.ts"],"sourcesContent":["import type { Ticker, TickerCallback } from './Ticker';\n\n/**\n * Internal class for handling the priority sorting of ticker handlers.\n * @private\n * @class\n */\nexport class TickerListener<T = any>\n{\n /** The current priority. */\n public priority: number;\n /** The next item in chain. */\n public next: TickerListener = null;\n /** The previous item in chain. */\n public previous: TickerListener = null;\n\n /** The handler function to execute. */\n private _fn: TickerCallback<T>;\n /** The calling to execute. */\n private _context: T;\n /** If this should only execute once. */\n private readonly _once: boolean;\n /** `true` if this listener has been destroyed already. */\n private _destroyed = false;\n\n /**\n * Constructor\n * @private\n * @param fn - The listener function to be added for one update\n * @param context - The listener context\n * @param priority - The priority for emitting\n * @param once - If the handler should fire once\n */\n constructor(fn: TickerCallback<T>, context: T = null, priority = 0, once = false)\n {\n this._fn = fn;\n this._context = context;\n this.priority = priority;\n this._once = once;\n }\n\n /**\n * Simple compare function to figure out if a function and context match.\n * @param fn - The listener function to be added for one update\n * @param context - The listener context\n * @returns `true` if the listener match the arguments\n */\n public match(fn: TickerCallback<T>, context: any = null): boolean\n {\n return this._fn === fn && this._context === context;\n }\n\n /**\n * Emit by calling the current function.\n * @param ticker - The ticker emitting.\n * @returns Next ticker\n */\n public emit(ticker: Ticker): TickerListener\n {\n if (this._fn)\n {\n if (this._context)\n {\n this._fn.call(this._context, ticker);\n }\n else\n {\n (this as TickerListener<any>)._fn(ticker);\n }\n }\n\n const redirect = this.next;\n\n if (this._once)\n {\n this.destroy(true);\n }\n\n // Soft-destroying should remove\n // the next reference\n if (this._destroyed)\n {\n this.next = null;\n }\n\n return redirect;\n }\n\n /**\n * Connect to the list.\n * @param previous - Input node, previous listener\n */\n public connect(previous: TickerListener): void\n {\n this.previous = previous;\n if (previous.next)\n {\n previous.next.previous = this;\n }\n this.next = previous.next;\n previous.next = this;\n }\n\n /**\n * Destroy and don't use after this.\n * @param hard - `true` to remove the `next` reference, this\n * is considered a hard destroy. Soft destroy maintains the next reference.\n * @returns The listener to redirect while emitting or removing.\n */\n public destroy(hard = false): TickerListener\n {\n this._destroyed = true;\n this._fn = null;\n this._context = null;\n\n // Disconnect, hook up next and previous\n if (this.previous)\n {\n this.previous.next = this.next;\n }\n\n if (this.next)\n {\n this.next.previous = this.previous;\n }\n\n // Redirect to the next item\n const redirect = this.next;\n\n // Remove references\n this.next = hard ? null : redirect;\n this.previous = null;\n\n return redirect;\n }\n}\n"],"names":[],"mappings":";AAOO,MAAM,cAAA,CACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBI,YAAY,EAAA,EAAuB,OAAA,GAAa,MAAM,QAAA,GAAW,CAAA,EAAG,OAAO,KAAA,EAC3E;AAtBA;AAAA,IAAA,IAAA,CAAO,IAAA,GAAuB,IAAA;AAE9B;AAAA,IAAA,IAAA,CAAO,QAAA,GAA2B,IAAA;AASlC;AAAA,IAAA,IAAA,CAAQ,UAAA,GAAa,KAAA;AAYjB,IAAA,IAAA,CAAK,GAAA,GAAM,EAAA;AACX,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAChB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAChB,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,KAAA,CAAM,EAAA,EAAuB,OAAA,GAAe,IAAA,EACnD;AACI,IAAA,OAAO,IAAA,CAAK,GAAA,KAAQ,EAAA,IAAM,IAAA,CAAK,QAAA,KAAa,OAAA;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,KAAK,MAAA,EACZ;AACI,IAAA,IAAI,KA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