feat: rip out mutations for templates

This commit is contained in:
Jonathan Kelley committed 2022-12-01 00:46:15 -05:00
1 parent 3b166c9edd
commit 85657d3906
33 files changed
+270 -314

No files matched your search

+5 -23
View File
@@ -2,7 +2,7 @@
use js_sys::Function;
use wasm_bindgen::prelude::*;
use web_sys::Element;
use web_sys::{Element, Node};
#[wasm_bindgen(module = "/src/interpreter.js")]
extern "C" {
@@ -12,29 +12,17 @@ extern "C" {
pub fn new(arg: Element) -> Interpreter;
#[wasm_bindgen(method)]
pub fn AppendChildren(this: &Interpreter, many: u32);
pub fn SaveTemplate(this: &Interpreter, nodes: Vec<Node>, name: &str);
#[wasm_bindgen(method)]
pub fn MountToRoot(this: &Interpreter);
#[wasm_bindgen(method)]
pub fn AssignId(this: &Interpreter, path: &[u8], id: u32);
#[wasm_bindgen(method)]
pub fn CreateElement(this: &Interpreter, tag: &str);
#[wasm_bindgen(method)]
pub fn CreateElementNs(this: &Interpreter, tag: &str, ns: &str);
#[wasm_bindgen(method)]
pub fn CreatePlaceholder(this: &Interpreter, id: u32);
#[wasm_bindgen(method)]
pub fn CreateStaticPlaceholder(this: &Interpreter);
#[wasm_bindgen(method)]
pub fn CreateTextPlaceholder(this: &Interpreter);
#[wasm_bindgen(method)]
pub fn CreateStaticText(this: &Interpreter, value: &str);
#[wasm_bindgen(method)]
pub fn CreateTextNode(this: &Interpreter, value: JsValue, id: u32);
@@ -56,15 +44,9 @@ extern "C" {
#[wasm_bindgen(method)]
pub fn InsertBefore(this: &Interpreter, id: u32, n: u32);
#[wasm_bindgen(method)]
pub fn SaveTemplate(this: &Interpreter, name: &str, m: u32);
#[wasm_bindgen(method)]
pub fn SetAttribute(this: &Interpreter, id: u32, name: &str, value: JsValue, ns: Option<&str>);
#[wasm_bindgen(method)]
pub fn SetStaticAttribute(this: &Interpreter, name: &str, value: JsValue, ns: Option<&str>);
#[wasm_bindgen(method)]
pub fn SetBoolAttribute(this: &Interpreter, id: u32, name: &str, value: bool);
+7 -26
View File
@@ -79,6 +79,13 @@ export class Interpreter {
pop() {
return this.stack.pop();
}
SaveTemplate(nodes, name) {
this.templates[name] = nodes;
console.log(this.templates);
}
MountToRoot() {
this.AppendChildren(this.stack.length - 1);
}
SetNode(id, node) {
this.nodes[id] = node;
}
@@ -132,25 +139,12 @@ export class Interpreter {
this.nodes[root] = node;
this.stack.push(node);
}
CreateElement(tag) {
const el = document.createElement(tag);
this.stack.push(el);
}
CreateElementNs(tag, ns) {
let el = document.createElementNS(ns, tag);
this.stack.push(el);
}
CreatePlaceholder(root) {
let el = document.createElement("pre");
el.hidden = true;
this.stack.push(el);
this.nodes[root] = el;
}
CreateStaticPlaceholder() {
let el = document.createElement("pre");
el.hidden = true;
this.stack.push(el);
}
NewEventListener(event_name, root, handler, bubbles) {
const element = this.nodes[root];
element.setAttribute("data-dioxus-id", `${root}`);
@@ -168,10 +162,6 @@ export class Interpreter {
const node = this.nodes[id];
this.SetAttributeInner(node, field, value, ns);
}
SetStaticAttribute(field, value, ns) {
const node = this.top();
this.SetAttributeInner(node, field, value, ns);
}
SetAttributeInner(node, field, value, ns) {
const name = field;
if (ns === "style") {
@@ -262,15 +252,6 @@ export class Interpreter {
this.nodes[id] = node;
this.stack.push(node);
}
SaveTemplate(name, m) {
this.templates[name] = this.stack.splice(this.stack.length - m);
}
CreateStaticText(text) {
this.CreateTextNode(text);
}
CreateTextPlaceholder() {
this.CreateRawText("placeholder");
}
handleEdit(edit) {
console.log(edit);
switch (edit.type) {