refactor(node-watcher): adapt to new DI architecture
This commit moves the node watcher code to the presentation layer and
adapts it to be ready to use DI. Thus, the node watcher is separated
into a port and adapter.
Bug: twpowertools:226
Change-Id: Id36d5407ff478006eb8c057db1dcad05fd30b7d6
diff --git a/src/common/architecture/scripts/nodeWatcher/LegacyNodeWatcherScript.ts b/src/common/architecture/scripts/nodeWatcher/LegacyNodeWatcherScript.ts
index b4c07a5..211210d 100644
--- a/src/common/architecture/scripts/nodeWatcher/LegacyNodeWatcherScript.ts
+++ b/src/common/architecture/scripts/nodeWatcher/LegacyNodeWatcherScript.ts
@@ -1,4 +1,4 @@
-import NodeWatcherSingleton from '../../../nodeWatcher/NodeWatcher';
+import NodeWatcherSingleton, { NodeWatcherAdapter } from '../../../../infrastructure/presentation/nodeWatcher/NodeWatcher.adapter';
import { ConcreteNodeWatcherScriptHandler } from './handlers/NodeWatcherScriptHandler';
import Script from '../Script';
@@ -11,22 +11,28 @@
ConcreteNodeWatcherScriptHandler<Options>
>;
+ private nodeWatcher: NodeWatcherAdapter;
+
+ constructor() {
+ super();
+
+ // TODO(https://iavm.xyz/b/226): Retrieve this via constructor injection.
+ this.nodeWatcher = NodeWatcherSingleton.getInstance();
+ }
+
/**
* Resolves to the options when the script is executed.
*
- * This is so we can defer retrieving dependencies until the script is
- * executed, to prevent loading unnecessary things if they aren't needed
- * after all.
*/
protected abstract optionsFactory(): Options;
execute() {
- const nodeWatcher = NodeWatcherSingleton.getInstance();
const options = this.optionsFactory();
+ this.nodeWatcher.start();
for (const [key, handlerClass] of this.handlers) {
const handler = new handlerClass(options);
- nodeWatcher.setHandler(key, handler);
+ this.nodeWatcher.setHandler(key, handler);
}
}
}
diff --git a/src/common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler.ts b/src/common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler.ts
index b5c3698..8756b72 100644
--- a/src/common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler.ts
+++ b/src/common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler.ts
@@ -1,5 +1,5 @@
import { NodeWatcherScriptHandler } from './NodeWatcherScriptHandler';
-import { NodeMutation, NodeMutationType } from '../../../../nodeWatcher/NodeWatcherHandler';
+import { NodeMutation, NodeMutationType } from '../../../../../presentation/nodeWatcher/NodeWatcherHandler';
/**
* @deprecated
diff --git a/src/common/architecture/scripts/nodeWatcher/handlers/NodeWatcherScriptHandler.ts b/src/common/architecture/scripts/nodeWatcher/handlers/NodeWatcherScriptHandler.ts
index 5b0fd42..712f533 100644
--- a/src/common/architecture/scripts/nodeWatcher/handlers/NodeWatcherScriptHandler.ts
+++ b/src/common/architecture/scripts/nodeWatcher/handlers/NodeWatcherScriptHandler.ts
@@ -1,4 +1,4 @@
-import { NodeMutation, NodeWatcherHandler } from "../../../../nodeWatcher/NodeWatcherHandler";
+import { NodeMutation, NodeWatcherHandler } from "../../../../../presentation/nodeWatcher/NodeWatcherHandler";
export abstract class NodeWatcherScriptHandler<Options>
implements NodeWatcherHandler