-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (36 loc) · 1.09 KB
/
index.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
import { Module } from '../Module';
import { Plugin } from '../Plugin';
import { NComponent } from './types';
export type { NComponent };
/**
* A class for Components.
*/
export class Component<
StaticProps extends NComponent.IStaticProps = NComponent.IStaticProps,
ChangeableProps extends
NComponent.IChangeableProps = NComponent.IChangeableProps,
CallbacksTypes extends
NComponent.ICallbacksTypes = NComponent.ICallbacksTypes,
> extends Module<StaticProps, ChangeableProps, CallbacksTypes> {
/** Inner plugins */
private _plugins?: Plugin[];
/** Add a single plugin */
public addPlugin<T extends Plugin<any, any, any, any>>(plugin: T) {
if (typeof this._plugins === 'undefined') {
this._plugins = [];
}
this._plugins.push(plugin);
// eslint-disable-next-line no-param-reassign
plugin.component = this;
plugin.init();
}
/** Destroy all plugins */
private _destroyPlugins() {
this._plugins?.forEach((plugin) => plugin.destroy());
}
/** Destroy the component */
protected _destroy() {
super._destroy();
this._destroyPlugins();
}
}