First commits be like

This commit is contained in:
2020-04-21 00:03:26 +02:00
parent f0e071212f
commit 93eea321a8
12 changed files with 440 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
export class BaseNode {
constructor(node) {
this.node = node;
}
}

View File

@@ -0,0 +1,22 @@
import { SwapNode } from "./swapnode.js";
import { PropertyReader } from "../propertyreader.js";
export class PropertyNode extends SwapNode {
constructor(node, swapNode, propertyReader) {
super(node, swapNode);
if (!(propertyReader instanceof PropertyReader))
throw TypeError("propertyReader must be an instance of PropertyReader");
this.propertyReader = propertyReader;
super.replaceNodes();
}
/**
* @override
*/
linker(node, swapNode) {
this.properties = this.propertyReader.read(node.innerText);
}
}

View File

@@ -0,0 +1,35 @@
import { BaseNode } from "./basenode.js";
export class SwapNode extends BaseNode {
constructor(node, swapNode) {
super(node);
if (!(swapNode instanceof Node))
throw TypeError("swapNode must be instance of Node");
this.swapNode = swapNode;
this.hasReplaceNodes = false;
}
replaceNodes() {
if (this.hasReplaceNodes)
return false;
this.linker(this.node, this.swapNode);
this.node.parentNode.replaceChild(this.swapNode, this.node);
this.node = this.swapNode;
delete this.swapNode;
return this.hasReplaceNodes = true;
}
/**
* Override this to have access to the script tag that gets converted to the new node inplace
* @param {Node} node Node of the original script tag
* @param {Node} swapNode Node of the new element that replaces the script tag inline
*/
linker(node, swapNode) {}
}