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