UNPKG

plugin-tls

Version:

plugin-tls 是插件系统相应的工具,可快速地让任何模块具备插件机制

141 lines (108 loc) 10.6 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [plugin-tls](./plugin-tls.md) &gt; [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)<!-- -->&lt;any, [IPlugin](./plugin-tls.iplugin.md)<!-- -->&lt;any, any&gt;&gt;; use&lt;P\_1 extends Plugin&gt;(plugin: P\_1, ...options: [FormatUsePluginParameters](./plugin-tls.formatusepluginparameters.md)<!-- -->&lt;P\_1&gt;): [PluginCreatedReturnType](./plugin-tls.plugincreatedreturntype.md)<!-- -->&lt;P\_1&gt; \| void; destroyThis(): void; readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDisposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; disposeObj&lt;T extends unknown&gt;(obj: T, sync?: boolean): T; cancelDisposeObj&lt;T extends unknown&gt;(obj: T): T; dispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; dispose&lt;T extends unknown&gt;(obj: T, asyncDestroy?: boolean): T; dispose&lt;T extends unknown&gt;(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDispose&lt;T extends unknown&gt;(obj: T): T; cancelDispose&lt;T extends unknown&gt;(objOrFun: T): T; destroy(): true \| undefined; destroyAsync(): Promise&lt;true \| undefined&gt;; constructor: Function; toString: (() =&gt; string) &amp; (() =&gt; string); toLocaleString: (() =&gt; string) &amp; (() =&gt; string); valueOf: (() =&gt; Object) &amp; (() =&gt; Object); hasOwnProperty: ((v: PropertyKey) =&gt; boolean) &amp; ((v: PropertyKey) =&gt; boolean); isPrototypeOf: ((v: Object) =&gt; boolean) &amp; ((v: Object) =&gt; boolean); propertyIsEnumerable: ((v: PropertyKey) =&gt; boolean) &amp; ((v: PropertyKey) =&gt; boolean); }; get pluginManager(): [PluginManager](./plugin-tls.pluginmanager.md)<!-- -->&lt;typeof [PluginHost](./plugin-tls.pluginhost.md) &amp; HOST &amp; (new (...args: any) =&gt; { readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDisposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; disposeObj&lt;T extends any&gt;(obj: T, sync?: boolean): T; cancelDisposeObj&lt;T extends any&gt;(obj: T): T; dispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; dispose&lt;T extends any&gt;(obj: T, asyncDestroy?: boolean): T; dispose&lt;T extends any \| import("@gby/destroyable").FunDestroyer&gt;(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDispose&lt;T extends any&gt;(obj: T): T; cancelDispose&lt;T extends any \| import("@gby/destroyable").FunDestroyer&gt;(objOrFun: T): T; destroyThis(): void; destroy(): true \| undefined; destroyAsync(): Promise&lt;true \| undefined&gt;; constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: PropertyKey): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: PropertyKey): boolean; }) &amp; P, Plugin&gt;; \_pluginManager: [PluginManager](./plugin-tls.pluginmanager.md)<!-- -->&lt;typeof [PluginHost](./plugin-tls.pluginhost.md) &amp; HOST &amp; (new (...args: any) =&gt; { readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: import("@gby/destroyable").FunDestroyer\[\]; disposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDisposeFun&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; disposeObj&lt;T extends any&gt;(obj: T, sync?: boolean): T; cancelDisposeObj&lt;T extends any&gt;(obj: T): T; dispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; dispose&lt;T extends any&gt;(obj: T, asyncDestroy?: boolean): T; dispose&lt;T extends any \| import("@gby/destroyable").FunDestroyer&gt;(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose&lt;T extends import("@gby/destroyable").FunDestroyer&gt;(fun: T): T; cancelDispose&lt;T extends any&gt;(obj: T): T; cancelDispose&lt;T extends any \| import("@gby/destroyable").FunDestroyer&gt;(objOrFun: T): T; destroyThis(): void; destroy(): true \| undefined; destroyAsync(): Promise&lt;true \| undefined&gt;; constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: PropertyKey): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: PropertyKey): boolean; }) &amp; P, Plugin&gt;; use&lt;P\_1 extends Plugin&gt;(plugin: P\_1, ...options: [FormatUsePluginParameters](./plugin-tls.formatusepluginparameters.md)<!-- -->&lt;P\_1&gt;): void \| ReturnType&lt;P\_1\["used"\]&gt;; } &amp; P ## Remarks 比 直接使用 PluginHost 提供了完善的类型推导 子类需要在构建函数中调用 `this.pluginManager.created(this);` 之所以没写在该类中的函数中,是因为 `this.pluginManager.created(this)` 通常会在构建函数执行的最后时才调用; 如果像下面写在该类的构建函数中,然后子类通过 `super()` 来调用,这样就会导致 `this.pluginManager.created(this)` 不是在最后的执行;