-
Notifications
You must be signed in to change notification settings - Fork 6
/
BaseModuleProvider.ts
47 lines (38 loc) · 1.32 KB
/
BaseModuleProvider.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
import SemanticVersion from '../semantic-version';
import { type IModuleProvider } from './IModuleProvider';
import { Subscription, type TeardownLogic } from 'rxjs';
export type BaseModuleProviderCtorArgs<TConfig = unknown> = {
version: string | SemanticVersion;
config: TConfig;
};
/**
* Base class for creating module provider
*
* this is the interface which is returned after enabling a module
*/
export abstract class BaseModuleProvider<TConfig = unknown> implements IModuleProvider {
#version: SemanticVersion;
#subscriptions: Subscription;
public get version() {
return this.#version;
}
constructor(args: BaseModuleProviderCtorArgs<TConfig>) {
this.#version = new SemanticVersion(args.version);
this.#subscriptions = new Subscription();
this._init(args.config);
}
protected abstract _init(config: TConfig): void;
/**
* Add teardown down function, which is called on dispose.
*
* @param teardown dispose callback function
* @returns callback for removing the teardown
*/
protected _addTeardown(teardown: Exclude<TeardownLogic, void>): VoidFunction {
this.#subscriptions.add(teardown);
return () => this.#subscriptions.remove(teardown);
}
public dispose() {
this.#subscriptions.unsubscribe();
}
}