quick-event
Version:
quick-event is a TypeScript event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With eventpp you can easily implement signal/slot mechanism, or observer pat
672 lines (665 loc) • 32.5 kB
TypeScript
/*!
* quick-event v0.1.4
* https://github.com/ArcherGu/quick-event.git
* @license MIT
*/
/**
* CallbackList is the fundamental class in quick-event. The other classes [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html) and [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html) are built on CallbackList.
*
* CallbackList holds a list of callbacks. At the time of the call, CallbackList simply invokes each callback one by one. Consider CallbackList as the signal/slot system in Qt, or the callback function pointer in some Windows APIs (such as lpCompletionRoutine in ReadFileEx).
* The *callback* can be any functions.
*
* ## Nested callback safety
* 1. If a callback adds another callback to the callback list during a invoking, the new callback is guaranteed not to be triggered within the same invoking. This is guaranteed by an integer counter. This rule will be broken is the counter is overflowed to zero in a invoking, but this rule will continue working on the subsequence invoking.<br/>
* 2. Any callbacks that are removed during a invoking are guaranteed not triggered.<br/>
*
* @export
* @class CallbackList
*/
declare class CallbackList {
private _head;
private _tail;
private _currentCounter;
private _canContinueInvoking;
private _argumentsAsArray;
private _dispatch;
private _applyDispatch;
constructor(params?: QuickEventParams);
/**
* The first [CallbackNode](https://archergu.github.io/quick-event/classes/callback_node.callbacknode.html)
*
* @readonly
* @memberof CallbackList
*/
get head(): CallbackNode | null;
/**
* The last [CallbackNode](https://archergu.github.io/quick-event/classes/callback_node.callbacknode.html)
*
* @readonly
* @memberof CallbackList
*/
get tail(): CallbackNode | null;
/**
* Add the *callback* to the callback list.<br/>
* The callback is added to the end of the callback list.<br/>
* Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.<br/>
* If `append` is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking.<br/>
* The time complexity is O(1).
*
* @param {Callback} callback
* @returns {CallbackNode}
* @memberof CallbackList
*/
append(callback: Callback): CallbackNode;
/**
* Add the *callback* to the callback list.<br/>
* The callback is added to the beginning of the callback list.<br/>
* Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.<br/>
* If `prepend` is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking.<br/>
* The time complexity is O(1).
*
* @param {Callback} callback
* @returns {CallbackNode}
* @memberof CallbackList
*/
prepend(callback: Callback): CallbackNode;
/**
* Insert the *callback* to the callback list before the callback *before*. If *before* is not found, *callback* is added at the end of the callback list.<br/>
* *before* can be a callback function, or a handle object.<br/>
* Return a handle object that represents the callback. The handle can be used to remove this callback or to insert additional callbacks before this callback.<br/>
* If `insert` is called in another callback during the invoking of the callback list, the new callback is guaranteed not to be triggered during the same callback list invoking.
* The time complexity is O(1).
*
* @param {Callback} callback
* @param {(Callback | CallbackNode | null | undefined)} before
* @returns {CallbackNode}
* @memberof CallbackList
*/
insert(callback: Callback, before: Callback | CallbackNode | null | undefined): CallbackNode;
/**
* Remove the callback from the callback list.<br/>
* *callback* can be a callback function, or a handle object.<br/>
* Return true if the callback is removed successfully, false if the callback is not found.<br/>
* The time complexity is O(1).
*
* @param {(Callback | CallbackNode | null | undefined)} handle
* @returns {boolean}
* @memberof CallbackList
*/
remove(handle: Callback | CallbackNode | null | undefined): boolean;
/**
* Return true if the callback list is empty.
*
* @returns {boolean}
* @memberof CallbackList
*/
empty(): boolean;
/**
* Return true if the callback list contains *callback*.<br/>
* *callback* can be a callback function, or a handle object.
*
* @param {(Callback | CallbackNode | null | undefined)} handle
* @returns {boolean}
* @memberof CallbackList
*/
has(handle: Callback | CallbackNode | null | undefined): boolean;
/**
* Return true if the callback list contains any callback.
*
* @returns
* @memberof CallbackList
*/
hasAny(): boolean;
/**
* Apply func to all callbacks.<br/>
* The `func` receives one parameter which is the callback.<br/>
* **Note**: the func can remove any callbacks, or add other callbacks, safely.
*
* @param {(callback: Callback) => any} func
* @memberof CallbackList
*/
forEach(func: (callback: Callback) => any): void;
/**
* Apply func to all callbacks. func must return a boolean value, and if the return value is false, forEachIf stops the looping immediately.<br/>
* Return true if all callbacks are invoked, or event is not found, false if func returns false.
*
* @param {(callback: Callback) => any} func
* @returns {boolean}
* @memberof CallbackList
*/
forEachIf(func: (callback: Callback) => any): boolean;
/**
* Invoke each callbacks in the callback list.<br/>
* The callbacks are called with arguments `arg1`, `arg2`, etc.
*
* @param {...any[]} args
* @memberof CallbackList
*/
dispatch(...args: any[]): void;
/**
* Invoke each callbacks in the callback list.<br/>
* The callbacks are called with arguments `arg1`, `arg2`, etc.<br/>
* Note the arguments are passed in an array, similar to Function.prototype.apply.
*
* @param {...any[]} args
* @memberof CallbackList
*/
applyDispatch(...args: any[]): void;
private _getNextCounter;
private _doFindNode;
private _dispatchArgumentsAsArray;
private _dispatchNotArgumentsAsArray;
private _applyDispatchArgumentsAsArray;
private _applyDispatchNotArgumentsAsArray;
}
/**
* MixinFilter allows all events are filtered or modified before dispatching.
*
* `MixinFilter.appendFilter(filter)` adds an event filter to the dispatcher. The `filter` receives an array same as mixinBeforeDispatch receives.
*
* The event filters are invoked for all events, and invoked before any listeners are invoked.
* The event filters can modify the arguments since the arguments are passed in the array.
*
* Event filter is a powerful and useful technology, below is some sample use cases, though the real world use cases are unlimited.
*
* 1, Capture and block all interested events. For example, in a GUI window system, all windows can receive mouse events. However, when a window is under mouse dragging, only the window under dragging should receive the mouse events even when the mouse is moving on other window. So when the dragging starts, the window can add a filter. The filter redirects all mouse events to the window and prevent other listeners from the mouse events, and bypass all other events.
*
* 2, Setup catch-all event listener. For example, in a phone book system, the system sends events based on the actions, such as adding a phone number, remove a phone number, look up a phone number, etc. A module may be only interested in special area code of a phone number, not the actions. One approach is the module can listen to all possible events (add, remove, look up), but this is very fragile -- how about a new action event is added and the module forgets to listen on it? The better approach is the module add a filter and check the area code in the filter.
* @export
* @class MixinFilter
* @example ```javascript
* let dispatcher = new EventDispatcher({
* mixins: [ new MixinFilter() ],
* argumentPassingMode: EventDispatcher.argumentPassingIncludeEvent
* });
*
* dispatcher.appendListener(3, (e, i, s) => {
* console.log("Got event 3, i was 1 but actural is", i, "s was Hello but actural is", s);
* });
* dispatcher.appendListener(5, () => {
* console.log("Shout not got event 5");
* });
*
* // Add three event filters.
*
* // The first filter modifies the input arguments to other values, then the subsequence filters
* // and listeners will see the modified values.
* dispatcher.appendFilter((args) => {
* console.log("Filter 1, e is", args[0], "passed in i is", args[1], "s is", args[2]);
* args[1] = 38;
* args[2] = "Hi";
* console.log("Filter 1, changed i is", args[1], "s is", args[2]);
* return true;
* });
*
* // The second filter filters out all event of 5. So no listeners on event 5 can be triggered.
* // The third filter is not invoked on event 5 also.
* dispatcher.appendFilter((args) => {
* console.log("Filter 2, e is", args[0], "passed in i is", args[1], "s is", args[2]);
* if(args[0] === 5) {
* return false;
* }
* return true;
* });
*
* // The third filter just prints the input arguments.
* dispatcher.appendFilter((args) => {
* console.log("Filter 3, e is", args[0], "passed in i is", args[1], "s is", args[2]);
* return true;
* });
*
* // Dispatch the events, the first argument is always the event type.
* dispatcher.dispatch(3, 1, "Hello");
* dispatcher.dispatch(5, 2, "World");
*
* // Output
* // > Filter 1, e is 3 passed in i is 1 s is Hello
* // > Filter 1, changed i is 38 s is Hi
* // > Filter 2, e is 3 passed in i is 38 s is Hi
* // > Filter 3, e is 3 passed in i is 38 s is Hi
* // > Got event 3, i was 1 but actural is 38 s was Hello but actural is Hi
* // > Filter 1, e is 5 passed in i is 2 s is World
* // > Filter 1, changed i is 38 s is Hi
* // > Filter 2, e is 5 passed in i is 38 s is Hi
* ```
*/
declare class MixinFilter {
filterList: CallbackList;
constructor(params?: QuickEventParams);
/**
* Add the *filter* to the dispatcher.<br/>
* Return a handle which can be used in removeFilter.
*
* @param {Filter} filter
* @returns {CallbackNode}
* @memberof MixinFilter
*/
appendFilter(filter: Filter): CallbackNode;
/**
* Remove a filter from the dispatcher.<br/>
* `filter` can be either the filter callback or the handle returned by `appendFilter`.<br/>
* Return true if the filter is removed successfully.
*
* @param {(Filter | CallbackNode)} handle
* @returns {boolean}
* @memberof MixinFilter
*/
removeFilter(handle: Filter | CallbackNode): boolean;
mixinBeforeDispatch(args: any[]): boolean;
}
declare enum ArgumentPassingMode {
IncludeEvent = 1,
ExcludeEvent = 2
}
/**
* All classes [CallbackList](https://archergu.github.io/quick-event/classes/callback_list.callbacklist.html), [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html) and [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html) in quick-event accepts a parameters object in constructor to configure and extend each components' behavior. The parameters object is `undefined` by default.<br/>
* All parameters are optional. If any parameter is omitted, the default value is used.<br/>
* The same parameter mechanism applies to all three classes, [CallbackList](https://archergu.github.io/quick-event/classes/callback_list.callbacklist.html), [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html) and [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html), though not all classes requires the same parameter.
*
* @export
* @interface QuickEventParams
*/
interface QuickEventParams {
/**
* The function receives same arguments as [EventDispatcher.dispatch](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html#dispatch) and [EventQueue.enqueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#enqueue), and must return an event type.<br/>
* quick-event forwards all arguments of [EventDispatcher.dispatch](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html#dispatch) and [EventQueue.enqueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#enqueue) (both has same arguments) to getEvent to get the event type, then invokes the callback list of the event type.
*
* @apply [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html), [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html)
* @default the default implementation returns the first argument of `getEvent`
* @memberof QuickEventParams
* @example ```javascript
* // The event object we will dispatch looks like,
* // MyEvent = {
* // type: int,
* // message: string,
* // param: int
* //};
*
* // When construct the dispatcher, pass the parameter
* // getEvent to indicate how to get the event type.
* let dispatcher = new EventDispatcher({
* getEvent: (e) => e.type
* });
*
* // Add a listener.
* // Note: the first argument is the event type of type int (same as the return type of getEvent), not MyEvent.
* // e is the main event object.
* // b is an extra parameter.
* dispatcher.appendListener(3, (e, b) => {
* console.log("Got event 3");
* console.log("Event::type is", e.type);
* console.log("Event::message is", e.message);
* console.log("Event::param is", e.param);
* console.log("b is", b);
* });
*
* // Dispatch the event.
* // The first argument is MyEvent.
* dispatcher.dispatch({ type: 3, message: "Hello world", param: 38 }, true);
*
* // Output:
* // > Got event 3
* // > Event::type is 3
* // > Event::message is Hello world
* // > Event::param is 38
* // > b is true
* ```
*/
getEvent?: (...args: any[]) => any;
/**
* `canContinueInvoking(arg1, arg2, ...)`. The function receives same arguments as [EventDispatcher.dispatch](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html#dispatch) and [EventQueue.enqueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#enqueue), and must return true if the event dispatching or callback list invoking can continue, false if the dispatching should stop.
*
* @apply [CallbackList](https://archergu.github.io/quick-event/classes/callback_list.callbacklist.html), [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html), [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html)
* @default the default implementation always returns true
* @memberof QuickEventParams
* @example ```javascript
* // The event object we will dispatch looks like,
* // MyEvent = {
* // type: int,
* // canceled: boolean
* //};
*
* // When construct the dispatcher, pass the parameter
* // getEvent to indicate how to get the event type.
* // Parameter canContinueInvoking checks if the dispatching can continue.
* let dispatcher = new EventDispatcher({
* getEvent: e => e.type,
*
* canContinueInvoking: (e) => ! e.canceled
* });
*
* dispatcher.appendListener(3, (e) => {
* console.log("Got event 3");
* e.canceled = true;
* });
* dispatcher.appendListener(3, (e) => {
* console.log("Should not get this event 3");
* });
*
* // Dispatch the event.
* // The first argument is MyEvent.
* dispatcher.dispatch({ type: 3, canceled: false });
* ```
*/
canContinueInvoking?: (...args: any[]) => boolean;
/**
* `ArgumentPassingMode` is the argument passing mode.
*
* The possible values,
*
* ```ts
* EventDispatcher.argumentPassingIncludeEvent = ArgumentPassingMode.IncludeEvent;
* EventDispatcher.argumentPassingExcludeEvent = ArgumentPassingMode.ExcludeEvent;
* ```
*
* The global default value,
*
* ```ts
* EventDispatcher.defaultArgumentPassingMode = ArgumentPassingMode.ExcludeEvent;
* ```
*
* Let's see some examples. Assume we have the dispatcher
* ```ts
* let dispatcher = new EventDispatcher();
* // same as
* let dispatcher = new EventDispatcher({ argumentPassingMode: EventDispatcher.argumentPassingExcludeEvent });
* dispatcher.dispatch(3, "hello");
* ```
* The listener will be invoked with the argument `("hello")`, the event type is omitted since it's argumentPassingExcludeEvent.
*
* @apply [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html), [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html)
* @default EventDispatcher.argumentPassingExcludeEvent
* @type {ArgumentPassingMode}
* @memberof QuickEventParams
*/
argumentPassingMode?: ArgumentPassingMode;
/**
* `argumentsAsArray` affects how the listeners and `getEvent` receive the arguments.
*
* When `argumentsAsArray` is false, the listeners and `getEvent` receive the arguments as individual parameters. For example,
*
* ```javascript
* let dispatcher = new EventDispatcher();
* // same as
* let dispatcher = new EventDispatcher({ argumentsAsArray: false });
* dispatcher.dispatch(a, b, c);
* // The listener will be called as
* myListener(a, b, c);
* ```
*
* When `argumentsAsArray` is true, the listeners and `getEvent` receive the arguments as an array of which each elements are the arguments. For example,
*
* ```javascript
* let dispatcher = new EventDispatcher({ argumentsAsArray: true });
* dispatcher.dispatch(a, b, c);
* // The listener will be called as
* myListener([ a, b, c ]);
* ```
*
* Setting `argumentsAsArray` to true will slightly improve the performance.
* @apply [CallbackList](https://archergu.github.io/quick-event/classes/callback_list.callbacklist.html), [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html), [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html)
* @default false
* @type {boolean}
* @memberof QuickEventParams
*/
argumentsAsArray?: boolean;
/**
* A mixin is used to inject code in the EventDispatcher/EventQueue inheritance hierarchy to extend the functionalities. For more details, please read the [document of mixins](https://github.com/ArcherGu/quick-event/blob/main/docs/md/mixins.md).
*
* @apply [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html), [EventQueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html)
* @default undefined
* @type {MixinFilter[]}
* @memberof QuickEventParams
*/
mixins?: MixinFilter[];
}
declare type Callback = (...args: any[]) => any;
declare type Filter = (...args: any[]) => boolean;
/**
* CallbackNode is used to record the structure of callbacks.<br/>
* The return value(`handle`) of some methods refers to CallbackNode.
*
* **Note:** Do not directly modify the structure of CallbackNode!
*
* @export
* @class CallbackNode
*/
declare class CallbackNode {
callback: Callback;
counter: number;
previous: CallbackNode | null;
next: CallbackNode | null;
constructor(callback: Callback, counter: number);
}
/**
* EventDispatcher is something like a map between the `EventType` and `CallbackList`.
*
* EventDispatcher holds a map of `<EventType, CallbackList>` pairs. On dispatching, EventDispatcher finds the CallbackList of the event type, then invoke the callback list. The invocation is always synchronous. The listeners are triggered when [EventDispatcher.dispatch](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html#dispatch) is called.
*
* ## Nested listener safety
* 1. If a listener adds another listener of the same event to the dispatcher during a dispatching, the new listener is guaranteed not to be triggered within the same dispatching. This is guaranteed by an unsigned 64 bits integer counter. This rule will be broken is the counter is overflowed to zero in a dispatching, but this rule will continue working on the subsequence dispatching.<br/>
* 2. Any listeners that are removed during a dispatching are guaranteed not triggered.
* @export
* @class EventDispatcher
*/
declare class EventDispatcher {
/**
* ArgumentPassingMode: IncludeEvent
* @static
* @readonly
* @memberof EventDispatcher
*/
static readonly argumentPassingIncludeEvent: ArgumentPassingMode;
/**
* ArgumentPassingMode: ExcludeEvent
* @static
* @readonly
* @memberof EventDispatcher
*/
static readonly argumentPassingExcludeEvent: ArgumentPassingMode;
/**
* ArgumentPassingMode: ExcludeEvent
* @static
* @readonly
* @memberof EventDispatcher
*/
static readonly defaultArgumentPassingMode: ArgumentPassingMode;
protected argumentsAsArray: boolean;
private _eventCallbackListMap;
private _params;
private _getEvent;
private _argumentPassingMode;
private _mixins;
constructor(params?: QuickEventParams);
/**
* Add the *callback* to the dispatcher to listen to *event*.<br/>
* The listener is added to the end of the listener list.<br/>
* Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.<br/>
* If `appendListener` is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.<br/>
* If the same callback is added twice, it results duplicated listeners.<br/>
* The time complexity is O(1).
*
* @param {(string | number)} event
* @param {Callback} callback
* @returns {CallbackNode}
* @memberof EventDispatcher
*/
appendListener(event: string | number, callback: Callback): CallbackNode;
/**
* Add the *callback* to the dispatcher to listen to *event*.<br/>
* The listener is added to the beginning of the listener list.<br/>
* Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.<br/>
* If `prependListener` is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.<br/>
* The time complexity is O(1).
*
* @param {(string | number)} event
* @param {Callback} callback
* @returns {CallbackNode}
* @memberof EventDispatcher
*/
prependListener(event: string | number, callback: Callback): CallbackNode;
/**
* Insert the *callback* to the dispatcher to listen to *event* before the listener handle *before*. If *before* is not found, *callback* is added at the end of the listener list.<br/>
* *before* can be a callback function, or a handle object.<br/>
* Return a handle object which represents the listener. The handle can be used to remove this listener or insert other listener before this listener.<br/>
* If `insertListener` is called in another listener during a dispatching, the new listener is guaranteed not triggered during the same dispatching.<br/>
* The time complexity is O(1).
*
* @param {(string | number)} event
* @param {Callback} callback
* @param {(Callback | CallbackNode | null | undefined)} before
* @returns {CallbackNode}
* @memberof EventDispatcher
*/
insertListener(event: string | number, callback: Callback, before: Callback | CallbackNode | null | undefined): CallbackNode;
/**
* Remove the listener *callback* which listens to *event* from the dispatcher.<br/>
* *callback* can be a callback function, or a handle object.<br/>
* Return true if the listener is removed successfully, false if the listener is not found.<br/>
* The time complexity is O(1).
*
* @param {(string | number)} event
* @param {(Callback | CallbackNode | null | undefined)} handle
* @returns {boolean}
* @memberof EventDispatcher
*/
removeListener(event: string | number, handle: Callback | CallbackNode | null | undefined): boolean;
/**
* Return true if the dispatcher contains *callback*.<br/>
* *callback* can be a callback function, or a handle object.
*
* @param {(string | number)} event
* @param {(Callback | CallbackNode | null | undefined)} handle
* @returns {boolean}
* @memberof EventDispatcher
*/
hasListener(event: string | number, handle: Callback | CallbackNode | null | undefined): boolean;
/**
* Return true if the dispatcher contains any callback.
*
* @param {(string | number)} event
* @returns {boolean}
* @memberof EventDispatcher
*/
hasAnyListener(event: string | number): boolean;
/**
* Dispatch an event.<br/>
* The listeners are called with arguments `arg1`, `arg2`, etc.
*
* @param {...any[]} args
* @memberof EventDispatcher
*/
dispatch(...args: any[]): void;
/**
* Dispatch an event.<br/>
* The listeners are called with arguments `arg1`, `arg2`, etc.<br/>
* Note the arguments are passed in an array, similar to Function.prototype.apply.
*
* @param {any[]} args
* @returns
* @memberof EventDispatcher
*/
applyDispatch(args: any[]): void;
/**
* Apply `func` to all listeners of `event`.<br/>
* The `func` receives one parameter which is the callback.<br/>
* **Note**: the `func` can remove any listeners, or add other listeners, safely.
*
* @param {(string | number)} event
* @param {(callback: Callback) => any} func
* @memberof EventDispatcher
*/
forEach(event: string | number, func: (callback: Callback) => any): void;
/**
* Apply `func` to all listeners of `event`. `func` must return a boolean value, and if the return value is false, forEachIf stops the looping immediately.<br/>
* Return `true` if all listeners are invoked, or `event` is not found, `false` if `func` returns `false`.
*
* @param {(string | number)} event
* @param {(callback: Callback) => any} func
* @returns {boolean}
* @memberof EventDispatcher
*/
forEachIf(event: string | number, func: (callback: Callback) => any): boolean;
private _doGetCallbackList;
}
/**
* EventQueue includes all features of [EventDispatcher](https://archergu.github.io/quick-event/classes/event_dispatcher.eventdispatcher.html) and adds event queue features.<br/>
* EventQueue is asynchronous. Events are cached in the queue when [EventQueue.enqueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#enqueue) is called, and dispatched later when [EventQueue.process](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#process) is called.<br/>
* EventQueue is equivalent to the event system (QEvent) in Qt, or the message processing in Windows API.
* @export
* @class EventQueue
* @extends {EventDispatcher}
*/
declare class EventQueue extends EventDispatcher {
private _queueList;
constructor(params?: QuickEventParams);
/**
* Put an event into the event queue.<br/>
* All arguments are copied to internal data structure.<br/>
* The time complexity is O(1).
*
* @param {...any[]} args
* @memberof EventQueue
*/
enqueue(...args: any[]): void;
/**
* Process the event queue. All events in the event queue are dispatched once and then removed from the queue.<br/>
* The function returns true if any events were processed, false if no event was processed.<br/>
* Any new events added to the queue during `process()` are not dispatched during current `process()`.
*
* @memberof EventQueue
*/
process(): void;
/**
* Process one event in the event queue. The first event in the event queue is dispatched once and then removed from the queue.<br/>
* The function returns true if one event was processed, false if no event was processed.<br/>
* Any new events added to the queue during `processOne()` are not dispatched during current `processOne()`.
*
* @memberof EventQueue
*/
processOne(): void;
/**
* Process the event queue. Before processing an event, the event is passed to `func` and the event will be processed only if `func` returns true.<br/>
* `func` takes exactly the same arguments as `EventQueue.enqueue`, and returns a boolean value.<br/>
* `processIf` returns true if any event was dispatched, false if no event was dispatched.<br/>
* `processIf` has some good use scenarios:<br/>
* 1. Process certain events. For example, in a GUI application, the UI related events may be only desired to processed by one module.<br/>
* 2. Process the events until certain time. For example, in a game engine, the event process may be limited to only several milliseconds, the remaining events will be process in next game loop.
*
* @param {(...args: any[]) => boolean} func
* @memberof EventQueue
*/
processIf(func: (...args: any[]) => boolean): void;
/**
* Return true if there is no any event in the event queue, false if there are any events in the event queue.
*
* @returns
* @memberof EventQueue
*/
empty(): boolean;
/**
* Clear all queued events without dispatching them.
*
* @memberof EventQueue
*/
clearEvents(): void;
/**
* Return a queued event from the queue.<br/>
* A queued event is an array with all arguments passed to [EventQueue.enqueue](https://archergu.github.io/quick-event/classes/event_queue.eventqueue.html#enqueue).<br/>
* If the queue is empty, the function returns null.<br/>
* After the function returns, the original even is still in the queue.
* @returns
* @memberof EventQueue
*/
peekEvent(): any;
/**
* Return an event from the queue and remove the original event from the queue.<br/>
* If the queue is empty, the function returns null.<br/>
* After the function returns, the original even is removed from the queue.
*
* @returns
* @memberof EventQueue
*/
takeEvent(): any;
}
export { ArgumentPassingMode, Callback, CallbackList, CallbackNode, EventDispatcher, EventQueue, Filter, MixinFilter, QuickEventParams };