-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
177 lines (177 loc) · 6.75 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Generated by "bundle-dts@1.1.1" https://github.com/fishen/bundle-dts#readme."
declare module "mp-event/src/constants" {
export const EVENT_OPTIONS: any;
}
declare module "mp-event/src/relect" {
import "reflect-metadata";
const reflect: typeof Reflect;
export default reflect;
}
declare module "mp-event/src/type" {
export type EventName = string | symbol;
export type BoundEvent = [IBindEventOptions, (...args: any) => any];
export interface IOffOptions<T = any> {
/**
* The value to be passed as the this parameter to the target function when the callback function is called
* Also used to distinguish different callback functions under the same event
*/
target?: T;
}
export interface IOnceOptions<T = any> extends IOffOptions<T> {
/**
* Register a unique callback function by event name and target
*/
unique?: boolean;
}
export interface IOnOptions<T = any> extends IOnceOptions<T> {
/**
* Whether the event is called only once
*/
once?: boolean;
}
export interface IEventOptions {
/**
* the lifetime for initializing events.
* @default onLoad
*/
onLifetime?: string;
/**
* the lifetime for deferring events.
* @default onShow
*/
deferralLifetime?: string;
/**
* the lifetime for destroying events.
* @default onUnload
*/
offLifetime?: string;
}
export interface IBindEventOptions extends Omit<IOnOptions, "target"> {
/**
* event name
*/
name?: EventName;
/**
* whether to delay execution to the specified lifetime, such as 'onShow'
*/
deferred?: boolean;
/**
* whether to trigger only once
*/
once?: boolean;
/**
* Whether to register as a global event
*/
global?: boolean;
}
}
declare module "mp-event/src/event" {
import { BoundEvent, IBindEventOptions, IEventOptions } from "mp-event/src/type";
export default class Event {
private static BOUND_EVENTS_KEY;
bind(options: IBindEventOptions, method: (...args: any) => any): void;
register(prototype: any, options: IEventOptions): Partial<Record<keyof IEventOptions, any>>;
destroy(events: BoundEvent[]): () => void;
protected getEvents(): BoundEvent[];
protected registerImplicitEvents(events: BoundEvent[], prototype: any, eventKey: symbol): () => void;
protected emitImplicitEvents(prototype: any, eventKey: symbol): () => void;
}
}
declare module "mp-event/src/deferral-event" {
import Event from "mp-event/src/event";
import { IEventOptions } from "mp-event/src/type";
export default class DeferralEvent extends Event {
private static DEFERRED_EVENTS;
register(prototype: any, options: IEventOptions): Partial<Record<keyof IEventOptions, any>>;
}
}
declare module "mp-event/src/global-event" {
import Event from "mp-event/src/event";
import { IEventOptions } from "mp-event/src/type";
export default class GlobalEvent extends Event {
private static GLOBAL_EVENTS;
register(prototype: any, options: IEventOptions): Partial<Record<keyof IEventOptions, any>>;
}
}
declare module "mp-event/src/global-deferral-event" {
import GlobalEvent from "mp-event/src/global-event";
import { IEventOptions } from "mp-event/src/type";
export default class GlobalDeferralEvent extends GlobalEvent {
register(prototype: any, options: IEventOptions): Partial<Record<keyof IEventOptions, any>>;
}
}
declare module "mp-event/src/event-manager" {
import Event from "mp-event/src/event";
import { IBindEventOptions, IEventOptions } from "mp-event/src/type";
export class EventManager {
static from(prototype: any): EventManager;
private static eventkey;
events: any;
create(options: IBindEventOptions): Event;
bind(options: IBindEventOptions, method: (...args: any) => any): void;
register(prototype: any, options: IEventOptions): void;
private get;
}
}
declare module "mp-event/src/events" {
import { EventName, IOffOptions, IOnceOptions, IOnOptions } from "mp-event/src/type";
/**
* Register an event subscription
* @param name event name
* @param callback callback function when the event is triggered
* @param options subscription options
*/
export function on<T>(name: EventName, callback: (this: T, result: any) => void, options?: IOnOptions<T>): void;
/**
* Register an event subscription, but only be triggered once
* @param name event name
* @param callback callback function when the event is triggered
* @param options subscription options
*/
export function once<T>(name: EventName, callback: (this: T, result: any) => void, options?: IOnceOptions<T>): void;
/**
* Cancel event subscription by name and target
* @param name event name
* @param options subscription options
*/
export function off<T>(name: EventName, options?: IOffOptions<T>): void;
/**
* Clear subscriptions by event name
* @param name event name
* @param clearAllIfNameIsNil whether clear all subscriptions if event name is null or undefined
*/
export function clear(name?: EventName, clearAllIfNameIsNil?: boolean): void;
/**
* Trigger event by name and data
* @param name event name
* @param data event data pass to the callback functions.
*/
export function emit<T>(name: EventName, data?: T): void;
}
declare module "mp-event/src/decoraters" {
import * as evt from "mp-event/src/events";
import { EventName, IBindEventOptions, IEventOptions } from "mp-event/src/type";
/**
* Register events and automatically unbind events when the page is destroyed.
* @param options event options
*/
export function event(options?: IEventOptions): (constructor: any) => void;
export namespace event {
var on: typeof evt.on;
var off: typeof evt.off;
var once: typeof evt.once;
var emit: typeof evt.emit;
var clear: typeof evt.clear;
var config: (options: IEventOptions, target?: any) => void;
}
/**
* Bind the current method as a callback function for the specified event
* @param options event options
*/
export function bindEvent(options?: EventName | IBindEventOptions): (target: any, name: EventName, descriptor: PropertyDescriptor) => void;
}
declare module "mp-event" {
export { bindEvent, event } from "mp-event/src/decoraters";
export { on, emit, once, off, clear } from "mp-event/src/events";
export { EVENT_OPTIONS } from "mp-event/src/constants";
}