-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseModule.ts
More file actions
48 lines (40 loc) · 1.4 KB
/
BaseModule.ts
File metadata and controls
48 lines (40 loc) · 1.4 KB
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
import type { Container } from '@needle-di/core';
import type { BaseOptions } from './index.ts';
import type { General, GeneralObject, ModuleInput as MI, Orchestratable } from './types.ts';
import type { Hook } from './utilities.ts';
type ModuleInput = MI<GeneralModuleCtor>;
export type GeneralModuleCtor = typeof BaseModule<General, General>;
export type BaseArgs = ConstructorParameters<GeneralModuleCtor>;
export type Options<M extends ModuleInput> = Orchestratable<M, 'options'>;
export type Augmentation<M extends ModuleInput> = Orchestratable<
M,
'_Augmentation'
>;
export class BaseModule<
O extends BaseOptions = BaseOptions,
A extends GeneralObject = {},
> {
declare private static readonly _BaseModuleBrand: unique symbol;
declare _Augmentation: A;
options: O;
onStart: Hook['subscribe'];
onDispose: Hook['subscribe'];
container: Container;
augment: (aug: A) => void;
constructor(
container: Container,
options: GeneralObject,
onStart: Hook,
onDispose: Hook,
augment: (aug: A) => void,
) {
this.container = container;
this.augment = augment;
// we assign the above two lines for Node.js compatibility. If you have a TypeScript compiler you can remove them and simply write in the constructor:
// protected container: Container,
// protected augment: (aug: A) => void,
this.options = options as O;
this.onStart = onStart.subscribe;
this.onDispose = onDispose.subscribe;
}
}