import type { Uint } from './defs'; export interface ListIterator { readonly prev: ListIterator; readonly next: ListIterator; readonly host: List | null; value: T; } export declare class List { private _length; private _end; get begin(): ListIterator; get end(): ListIterator; get length(): number; get front(): T | undefined; get back(): T | undefined; constructor(); toArray(): T[]; remove(it: ListIterator): ListIterator; erase(begin: ListIterator, end: ListIterator): void; insert(after: ListIterator, value: T): ListIterator; splice(it: ListIterator, from_begin: ListIterator, from_end: ListIterator): void; spliceAll(it: ListIterator, from: List): void; pushBack(value: T): ListIterator; pushFront(value: T): ListIterator; popBack(): void; popFront(): void; clear(): void; } /** * @class Event The event data */ export declare class Event { private _sender; private _data; /** The return value */ returnValue: Uint; /** The Data */ get data(): SendData; /** The sender */ get sender(): Sender; /** */ constructor(data: SendData); } /** * @template E,Ctx * @callback Listen(this:Ctx,evt:E)any */ export interface Listen { (this: Ctx, evt: E): any; } /** * @template E,Ctx * @callback Listen2(self:Ctx,evt:E)any */ export interface Listen2 { (self: Ctx, evt: E): any; } export type DataOf = T extends Event ? D : never; export type SenderOf = T extends Event ? S : never; /** * @class EventNoticer * * Event notifier, the core of event listener adding, deleting, triggering and notification */ export declare class EventNoticer { private _name; private _sender; private _listens?; private _listens_map?; private _length; private _add; /** Event name */ get name(): string; /** * @get sender:any Event sender */ get sender(): SenderOf; /** * @get length Number of event listeners */ get length(): Uint; /** * @param name Event name * @param sender Event sender */ constructor(name: string, sender: SenderOf); /** * Add an event listener (function) * @param listen Listening Function * @param ctxOrId? Specify the listener function this or id alias * @param id? Listener alias, can be deleted by id * @return Returns the passed `id` or the automatically generated `id` * @example * ```ts * var ctx = { a:100 } * var id = screen.onChange.on(function(ev) { * // Prints: 100 * console.log(this.a) * }, ctx) * // Replace Listener * screen.onChange.on(function(ev) { * // Prints: replace 100 * console.log('replace', this.a) * }, ctx, id) * ``` */ on(listen: Listen, ctxOrId?: Ctx | string, id?: string): string; /** * Add an event listener (function), * and "on" the same processor of the method to add the event trigger to receive two parameters * @param listen Listening Function * @param ctxOrId? Specify the listener function this or id alias * @param id? Listener alias, can be deleted by id * @return Returns the passed `id` or the automatically generated `id` * * * Example: * * ```js * var ctx = { a:100 } * var id = display_port.onChange.on2(function(ctx, ev) { * // Prints: 100 * console.log(ctx.a) * }, ctx) * ``` */ on2(listen: Listen2, ctxOrId?: Ctx | string, id?: string): string; /** Forward the event to another noticer */ forward(noticer: EventNoticer, id?: string): string; /** * Set the lifespan of the listener function with the specified `id` * @param id Listener id * @param lifespan Lifespan, the number of times the listener is valid, default is 1 */ setLifespan(id: string, lifespan?: Uint): void; /** * Notify all observers */ trigger(data: DataOf): void; /** * Notify all observers */ triggerWithEvent(e: E): void; /** * Remove listener function * @param listen? * It can be a listener function/id alias. * If no parameter is passed, all listeners will be uninstalled. * @param ctx? Context object, only valid when `listen` is a function * @return {Uint} Returns the number of deleted listeners */ off(listen?: Function | string, ctx?: object): Uint; /** * Remove all listeners related to `ctx` on this noticer */ offByCtx(ctx: object): Uint; } /** * @class Notification * * This is a collection of events `EventNoticer`, event triggering and response center * * Derived types inherited from it can use the `@event` keyword to declare member events * */ export declare class Notification { /** * @method getNoticer(name) */ getNoticer(name: string): EventNoticer; /** * @method hasNoticer(name)bool */ hasNoticer(name: string): boolean; /** * @method addDefaultListener(name,listen) */ addDefaultListener(name: string, listen: Listen | null): void; /** * call: [`EventNoticer.on(listen,ctxOrId?,id?)`] */ addEventListener(name: string, listen: Listen, ctxOrId?: Ctx | string, id?: string): string; /** * call: [`EventNoticer.on2(listen,ctxOrId?,id?)`] */ addEventListener2(name: string, listen: Listen2, ctxOrId?: Ctx | string, id?: string): string; /** * call: [`EventNoticer.forward(noticer,id?)`] */ addEventForward(name: string, noticer: EventNoticer, id?: string): string; /** * call: [`EventNoticer.setLifespan(id,lifespan)`] */ setEventListenerLifespan(name: string, id: string, lifespan?: Uint): void; /** * Trigger an event by event name --> [`EventNoticer.trigger(data)`] */ trigger(name: string, data: DataOf): void; /** * Trigger an event by name and [`Event`] --> [`EventNoticer.triggerWithEvent(event)`] */ triggerWithEvent(name: string, event: E): void; /** * Remove listener function * @param name Event name * @param listen? It can be a listener function/id alias. * If no parameter is passed, all listeners will be uninstalled. * @param ctx? Context object, only valid when `listen` is a function */ removeEventListener(name: string, listen?: Function | string, ctx?: object): void; /** * Delete all listeners related to `ctx` on `notification` * * Actually traverse and call the [`EventNoticer.offByCtx(ctx)`] method * * @example * * ```ts * import event from 'quark/event'; * * class TestNotification extends Notification { * \@event readonly onChange; * } * * var notification = new TestNotification(); * // Prints: responseonChange 0 100 * notification.onChange = function(ev) { // add default listener * console.log('responseonChange 0', ev.data) * } * notification.triggerChange(100); * * // Prints: * // responseonChange 0 200 * // responseonChange 1 * notification.onChange.on(function(ev) { * console.log('responseonChange 1') * }) * notification.triggerWithEvent('change', new Event(200)); * * var noticer = notification.onChange; * noticer.off(0) // delete default listener * // Prints: responseonChange 1 * notification.triggerChange(); * * ``` */ removeEventListenerByCtx(ctx: object): void; /** * Get all of [`EventNoticer`] */ allNoticers(): EventNoticer[]; /** */ triggerListenerChange(name: string, count: Uint, change: Uint): void; } /** * Typescript decorator * @decorator */ export declare function event(target: any, name: string): void;