-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
60 lines (41 loc) · 1.83 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
export type Context = {
key: string
id: number
cycleOf: <T>(name: string) => T
}
export type ObjectBuilderType<T = any> = (ctx: Context) => T
export type DefineContext<T = any> = {
withTrait: (traits: { [key: string]: ObjectBuilderType<T> }) => DefineContext<T>
withResource: (resources: { [key: string]: any[] }) => DefineContext<T>
onCreate: <U>(func: (object: T) => U) => DefineContext<T>
onCreateWithClass: <U extends { new(attr: T): any }>(clazz: U) => DefineContext<T>
}
export interface IFactoryPool {
nextId(key: string): number
resetAllId(): void
resetId(key: string): void
addDefine(key: string, func: ObjectBuilderType): void
getDefine(key: string): ObjectBuilderType
addTrait(key: string, name: string, func: ObjectBuilderType): void
getTrait(key: string, name: string): ObjectBuilderType
addResource(key: string, name: string, resource: any[]): void
getResource<T>(key: string, name: string): T[]
addCreator(key: string, func: Function): void
getCreator(key: string): Function
}
export declare const define: <T, U = Partial<T>>(
key: string, func: ObjectBuilderType<T>) => DefineContext<U>
export declare const build: <T, U = Partial<T>>(
key: string, traitNames?: string[] | undefined, option?: U | undefined) => U & T
export declare const create: <T, U = Partial<T>, V = any>(
key: string, traitNames?: string[] | undefined, option?: U | undefined) => V
declare const ObjectFactory: {
factoryPool: IFactoryPool
define: <T, U = Partial<T>>(
key: string, func: ObjectBuilderType<T>) => DefineContext<U>
build: <T_1, U_1 = Partial<T_1>>(
key: string, traitNames?: string[] | undefined, option?: U_1 | undefined) => U_1 & T_1
create: <T_2, U_2 = Partial<T_2>, V = any>(
key: string, traitNames?: string[] | undefined, option?: U_2 | undefined) => V
}
export default ObjectFactory