plugin-tls
Version:
plugin-tls 是插件系统相应的工具,可快速地让任何模块具备插件机制
141 lines (108 loc) • 10.6 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [plugin-tls](./plugin-tls.md) > [createPluginHost](./plugin-tls.createpluginhost.md)
## createPluginHost() function
创建插件的缩主类
**Signature:**
```typescript
export declare function createPluginHost<HOST, P extends new (...args: any) => Object, Plugin extends IPlugin<HOST, any> = IPlugin<HOST, any>>(ParentClass: P): {
new (...args: any): {
get pluginManager(): PluginManager<any, IPlugin<any, any>>;
use<P_1 extends Plugin>(plugin: P_1, ...options: FormatUsePluginParameters<P_1>): PluginCreatedReturnType<P_1> | void;
destroyThis(): void;
readonly isDestroyed: boolean;
_isDestroyed: boolean;
_destroyers: import("@gby/destroyable").FunDestroyer[];
disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
disposeObj<T extends unknown>(obj: T, sync?: boolean): T;
cancelDisposeObj<T extends unknown>(obj: T): T;
dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
dispose<T extends unknown>(obj: T, asyncDestroy?: boolean): T;
dispose<T extends unknown>(objOrFun: T, asyncDestroy?: boolean): T;
cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDispose<T extends unknown>(obj: T): T;
cancelDispose<T extends unknown>(objOrFun: T): T;
destroy(): true | undefined;
destroyAsync(): Promise<true | undefined>;
constructor: Function;
toString: (() => string) & (() => string);
toLocaleString: (() => string) & (() => string);
valueOf: (() => Object) & (() => Object);
hasOwnProperty: ((v: PropertyKey) => boolean) & ((v: PropertyKey) => boolean);
isPrototypeOf: ((v: Object) => boolean) & ((v: Object) => boolean);
propertyIsEnumerable: ((v: PropertyKey) => boolean) & ((v: PropertyKey) => boolean);
};
get pluginManager(): PluginManager<typeof PluginHost & HOST & (new (...args: any) => {
readonly isDestroyed: boolean;
_isDestroyed: boolean;
_destroyers: import("@gby/destroyable").FunDestroyer[];
disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
disposeObj<T extends any>(obj: T, sync?: boolean): T;
cancelDisposeObj<T extends any>(obj: T): T;
dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
dispose<T extends any>(obj: T, asyncDestroy?: boolean): T;
dispose<T extends any | import("@gby/destroyable").FunDestroyer>(objOrFun: T, asyncDestroy?: boolean): T;
cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDispose<T extends any>(obj: T): T;
cancelDispose<T extends any | import("@gby/destroyable").FunDestroyer>(objOrFun: T): T;
destroyThis(): void;
destroy(): true | undefined;
destroyAsync(): Promise<true | undefined>;
constructor: Function;
toString(): string;
toLocaleString(): string;
valueOf(): Object;
hasOwnProperty(v: PropertyKey): boolean;
isPrototypeOf(v: Object): boolean;
propertyIsEnumerable(v: PropertyKey): boolean;
}) & P, Plugin>;
_pluginManager: PluginManager<typeof PluginHost & HOST & (new (...args: any) => {
readonly isDestroyed: boolean;
_isDestroyed: boolean;
_destroyers: import("@gby/destroyable").FunDestroyer[];
disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
disposeObj<T extends any>(obj: T, sync?: boolean): T;
cancelDisposeObj<T extends any>(obj: T): T;
dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
dispose<T extends any>(obj: T, asyncDestroy?: boolean): T;
dispose<T extends any | import("@gby/destroyable").FunDestroyer>(objOrFun: T, asyncDestroy?: boolean): T;
cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T;
cancelDispose<T extends any>(obj: T): T;
cancelDispose<T extends any | import("@gby/destroyable").FunDestroyer>(objOrFun: T): T;
destroyThis(): void;
destroy(): true | undefined;
destroyAsync(): Promise<true | undefined>;
constructor: Function;
toString(): string;
toLocaleString(): string;
valueOf(): Object;
hasOwnProperty(v: PropertyKey): boolean;
isPrototypeOf(v: Object): boolean;
propertyIsEnumerable(v: PropertyKey): boolean;
}) & P, Plugin>;
use<P_1 extends Plugin>(plugin: P_1, ...options: FormatUsePluginParameters<P_1>): void | ReturnType<P_1["used"]>;
} & P;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
ParentClass
</td><td>
P
</td><td>
</td></tr>
</tbody></table>
**Returns:**
{ new (...args: any): { get pluginManager(): [PluginManager](./plugin-tls.pluginmanager.md)<!-- --><any, [IPlugin](./plugin-tls.iplugin.md)<!-- --><any, any>>; use<P\_1 extends Plugin>(plugin: P\_1, ...options: [FormatUsePluginParameters](./plugin-tls.formatusepluginparameters.md)<!-- --><P\_1>): [PluginCreatedReturnType](./plugin-tls.plugincreatedreturntype.md)<!-- --><P\_1> \| void; destroyThis(): void; readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; disposeObj<T extends unknown>(obj: T, sync?: boolean): T; cancelDisposeObj<T extends unknown>(obj: T): T; dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; dispose<T extends unknown>(obj: T, asyncDestroy?: boolean): T; dispose<T extends unknown>(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDispose<T extends unknown>(obj: T): T; cancelDispose<T extends unknown>(objOrFun: T): T; destroy(): true \| undefined; destroyAsync(): Promise<true \| undefined>; constructor: Function; toString: (() => string) & (() => string); toLocaleString: (() => string) & (() => string); valueOf: (() => Object) & (() => Object); hasOwnProperty: ((v: PropertyKey) => boolean) & ((v: PropertyKey) => boolean); isPrototypeOf: ((v: Object) => boolean) & ((v: Object) => boolean); propertyIsEnumerable: ((v: PropertyKey) => boolean) & ((v: PropertyKey) => boolean); }; get pluginManager(): [PluginManager](./plugin-tls.pluginmanager.md)<!-- --><typeof [PluginHost](./plugin-tls.pluginhost.md) & HOST & (new (...args: any) => { readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; disposeObj<T extends any>(obj: T, sync?: boolean): T; cancelDisposeObj<T extends any>(obj: T): T; dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; dispose<T extends any>(obj: T, asyncDestroy?: boolean): T; dispose<T extends any \| import("@gby/destroyable").FunDestroyer>(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDispose<T extends any>(obj: T): T; cancelDispose<T extends any \| import("@gby/destroyable").FunDestroyer>(objOrFun: T): T; destroyThis(): void; destroy(): true \| undefined; destroyAsync(): Promise<true \| undefined>; constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: PropertyKey): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: PropertyKey): boolean; }) & P, Plugin>; \_pluginManager: [PluginManager](./plugin-tls.pluginmanager.md)<!-- --><typeof [PluginHost](./plugin-tls.pluginhost.md) & HOST & (new (...args: any) => { readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDisposeFun<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; disposeObj<T extends any>(obj: T, sync?: boolean): T; cancelDisposeObj<T extends any>(obj: T): T; dispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; dispose<T extends any>(obj: T, asyncDestroy?: boolean): T; dispose<T extends any \| import("@gby/destroyable").FunDestroyer>(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose<T extends import("@gby/destroyable").FunDestroyer>(fun: T): T; cancelDispose<T extends any>(obj: T): T; cancelDispose<T extends any \| import("@gby/destroyable").FunDestroyer>(objOrFun: T): T; destroyThis(): void; destroy(): true \| undefined; destroyAsync(): Promise<true \| undefined>; constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: PropertyKey): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: PropertyKey): boolean; }) & P, Plugin>; use<P\_1 extends Plugin>(plugin: P\_1, ...options: [FormatUsePluginParameters](./plugin-tls.formatusepluginparameters.md)<!-- --><P\_1>): void \| ReturnType<P\_1\["used"\]>; } & P
## Remarks
比 直接使用 PluginHost 提供了完善的类型推导
子类需要在构建函数中调用 `this.pluginManager.created(this);`
之所以没写在该类中的函数中,是因为 `this.pluginManager.created(this)` 通常会在构建函数执行的最后时才调用; 如果像下面写在该类的构建函数中,然后子类通过 `super()` 来调用,这样就会导致 `this.pluginManager.created(this)` 不是在最后的执行;