blob: 2c9b91ed3f6bb582142736986d703862e5f5d3c1 [file] [log] [blame]
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +02001import NodeWatcherSingleton from '../../../nodeWatcher/NodeWatcher';
2import { ConcreteNodeWatcherScriptHandler } from './handlers/NodeWatcherScriptHandler';
3import Script from '../Script';
4
5export default abstract class NodeWatcherScript<Options> extends Script {
6 public abstract handlers: Map<
7 string,
8 ConcreteNodeWatcherScriptHandler<Options>
9 >;
10
11 /**
12 * Resolves to the options when the script is executed.
13 *
14 * This is so we can defer retrieving dependencies until the script is
15 * executed, to prevent loading unnecessary things if they aren't needed
16 * after all.
17 */
18 protected abstract optionsFactory(): Options;
19
20 execute() {
21 const nodeWatcher = NodeWatcherSingleton.getInstance();
22 const options = this.optionsFactory();
23
24 for (const [key, handlerClass] of this.handlers) {
25 const handler = new handlerClass(options);
26 nodeWatcher.setHandler(key, handler);
27 }
28 }
29}