refactor(autorefresh): migrate to the new DI architecture
The presentation layer has been updated to use DI for the Autorefresh
feature.
Since it's the first feature using DI, this commit also refactors the
main and start entry points to set up the script runner using DI.
Compatibility with the old feature architecture (what we used to call
"new architecture") has been provided as well, so other features which
haven't migrated yet to use DI continue to work properly.
Bug: twpowertools:226
Change-Id: Icf97bebe761693571f3aa915a4935bc002e7c0ca
diff --git a/src/infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter.ts b/src/infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter.ts
new file mode 100644
index 0000000..bf57020
--- /dev/null
+++ b/src/infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter.ts
@@ -0,0 +1,32 @@
+import {
+ NodeMutation,
+ NodeMutationType,
+ NodeWatcherHandler,
+} from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+
+export default abstract class CssSelectorNodeWatcherHandler
+ implements NodeWatcherHandler
+{
+ readonly mutationTypesProcessed: NodeMutationType[] = [
+ NodeMutationType.InitialDiscovery,
+ NodeMutationType.NewNode,
+ ];
+
+ abstract readonly cssSelector: string;
+
+ nodeFilter(nodeMutation: NodeMutation): boolean {
+ if (
+ !this.mutationTypesProcessed.includes(nodeMutation.type) ||
+ !(nodeMutation.node instanceof Element)
+ ) {
+ return false;
+ }
+ return nodeMutation.node.matches(this.cssSelector);
+ }
+
+ get initialDiscoverySelector() {
+ return this.cssSelector;
+ }
+
+ abstract onMutatedNode(nodeMutation: NodeMutation): void;
+}