chore: continue to clean things up
This commit is contained in:
1 parent
85657d3906
commit
11a45c8ef0
5 files changed
+23
-50
No files matched your search
@@ -131,11 +131,18 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Default)]
|
|
||||||
pub struct EventHandler<'bump, T = ()> {
|
pub struct EventHandler<'bump, T = ()> {
|
||||||
pub(super) callback: RefCell<Option<ExternalListenerCallback<'bump, T>>>,
|
pub(super) callback: RefCell<Option<ExternalListenerCallback<'bump, T>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Default for EventHandler<'_, T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
callback: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ExternalListenerCallback<'bump, T> = bumpalo::boxed::Box<'bump, dyn FnMut(T) + 'bump>;
|
type ExternalListenerCallback<'bump, T> = bumpalo::boxed::Box<'bump, dyn FnMut(T) + 'bump>;
|
||||||
|
|
||||||
impl<T> EventHandler<'_, T> {
|
impl<T> EventHandler<'_, T> {
|
||||||
|
|||||||
@@ -489,8 +489,7 @@ impl VirtualDom {
|
|||||||
match unsafe { self.run_scope(ScopeId(0)).extend_lifetime_ref() } {
|
match unsafe { self.run_scope(ScopeId(0)).extend_lifetime_ref() } {
|
||||||
// Rebuilding implies we append the created elements to the root
|
// Rebuilding implies we append the created elements to the root
|
||||||
RenderReturn::Sync(Ok(node)) => {
|
RenderReturn::Sync(Ok(node)) => {
|
||||||
let m = self.create_scope(ScopeId(0), node);
|
let _m = self.create_scope(ScopeId(0), node);
|
||||||
// self.mutations.push(Mutation::AppendChildren { m });
|
|
||||||
}
|
}
|
||||||
// If an error occurs, we should try to render the default error component and context where the error occured
|
// If an error occurs, we should try to render the default error component and context where the error occured
|
||||||
RenderReturn::Sync(Err(e)) => panic!("Cannot catch errors during rebuild {:?}", e),
|
RenderReturn::Sync(Err(e)) => panic!("Cannot catch errors during rebuild {:?}", e),
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
export function main() {
|
export function main() {
|
||||||
let root = window.document.getElementById("main");
|
let root = window.document.getElementById("main");
|
||||||
console.log("loading!");
|
|
||||||
if (root != null) {
|
if (root != null) {
|
||||||
window.interpreter = new Interpreter(root);
|
window.interpreter = new Interpreter(root);
|
||||||
console.log("properly loaded!");
|
|
||||||
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +16,6 @@ class ListenerMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create(event_name, element, handler, bubbles) {
|
create(event_name, element, handler, bubbles) {
|
||||||
console.log("creating listener for", event_name, element, handler, bubbles);
|
|
||||||
if (bubbles) {
|
if (bubbles) {
|
||||||
if (this.global[event_name] === undefined) {
|
if (this.global[event_name] === undefined) {
|
||||||
this.global[event_name] = {};
|
this.global[event_name] = {};
|
||||||
@@ -81,7 +78,6 @@ export class Interpreter {
|
|||||||
}
|
}
|
||||||
SaveTemplate(nodes, name) {
|
SaveTemplate(nodes, name) {
|
||||||
this.templates[name] = nodes;
|
this.templates[name] = nodes;
|
||||||
console.log(this.templates);
|
|
||||||
}
|
}
|
||||||
MountToRoot() {
|
MountToRoot() {
|
||||||
this.AppendChildren(this.stack.length - 1);
|
this.AppendChildren(this.stack.length - 1);
|
||||||
@@ -131,8 +127,7 @@ export class Interpreter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CreateRawText(text) {
|
CreateRawText(text) {
|
||||||
const node = document.createTextNode(text);
|
this.stack.push(document.createTextNode(text));
|
||||||
this.stack.push(node);
|
|
||||||
}
|
}
|
||||||
CreateTextNode(text, root) {
|
CreateTextNode(text, root) {
|
||||||
const node = document.createTextNode(text);
|
const node = document.createTextNode(text);
|
||||||
@@ -218,8 +213,6 @@ export class Interpreter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleEdits(edits) {
|
handleEdits(edits) {
|
||||||
console.log("handling edits", edits, this.stack.length);
|
|
||||||
|
|
||||||
for (let edit of edits) {
|
for (let edit of edits) {
|
||||||
this.handleEdit(edit);
|
this.handleEdit(edit);
|
||||||
}
|
}
|
||||||
@@ -253,7 +246,6 @@ export class Interpreter {
|
|||||||
this.stack.push(node);
|
this.stack.push(node);
|
||||||
}
|
}
|
||||||
handleEdit(edit) {
|
handleEdit(edit) {
|
||||||
console.log(edit);
|
|
||||||
switch (edit.type) {
|
switch (edit.type) {
|
||||||
case "AppendChildren":
|
case "AppendChildren":
|
||||||
this.AppendChildren(edit.m);
|
this.AppendChildren(edit.m);
|
||||||
@@ -261,27 +253,9 @@ export class Interpreter {
|
|||||||
case "AssignId":
|
case "AssignId":
|
||||||
this.AssignId(edit.path, edit.id);
|
this.AssignId(edit.path, edit.id);
|
||||||
break;
|
break;
|
||||||
case "CreateElement":
|
|
||||||
this.CreateElement(edit.name);
|
|
||||||
break;
|
|
||||||
case "CreateElementNs":
|
|
||||||
this.CreateElementNs(edit.name, edit.namespace);
|
|
||||||
break;
|
|
||||||
case "CreatePlaceholder":
|
case "CreatePlaceholder":
|
||||||
this.CreatePlaceholder(edit.id);
|
this.CreatePlaceholder(edit.id);
|
||||||
break;
|
break;
|
||||||
case "CreateStaticText":
|
|
||||||
this.CreateStaticText(edit.value)
|
|
||||||
break;
|
|
||||||
case "CreateStaticPlaceholder":
|
|
||||||
this.CreateStaticPlaceholder();
|
|
||||||
break;
|
|
||||||
case "CreateTextPlaceholder":
|
|
||||||
this.CreateTextPlaceholder();
|
|
||||||
break;
|
|
||||||
case "CreateStaticText":
|
|
||||||
this.CreateRawText(edit.value);
|
|
||||||
break;
|
|
||||||
case "CreateTextNode":
|
case "CreateTextNode":
|
||||||
this.CreateTextNode(edit.value);
|
this.CreateTextNode(edit.value);
|
||||||
break;
|
break;
|
||||||
@@ -291,9 +265,6 @@ export class Interpreter {
|
|||||||
case "LoadTemplate":
|
case "LoadTemplate":
|
||||||
this.LoadTemplate(edit.name, edit.index, edit.id);
|
this.LoadTemplate(edit.name, edit.index, edit.id);
|
||||||
break;
|
break;
|
||||||
case "SaveTemplate":
|
|
||||||
this.SaveTemplate(edit.name, edit.m);
|
|
||||||
break;
|
|
||||||
case "PushRoot":
|
case "PushRoot":
|
||||||
this.PushRoot(edit.id);
|
this.PushRoot(edit.id);
|
||||||
break;
|
break;
|
||||||
@@ -318,15 +289,9 @@ export class Interpreter {
|
|||||||
case "SetAttribute":
|
case "SetAttribute":
|
||||||
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
||||||
break;
|
break;
|
||||||
case "SetStaticAttribute":
|
|
||||||
this.SetStaticAttribute(edit.name, edit.value, edit.ns);
|
|
||||||
break;
|
|
||||||
case "SetBoolAttribute":
|
case "SetBoolAttribute":
|
||||||
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
||||||
break;
|
break;
|
||||||
case "SetInnerText":
|
|
||||||
console.log("Set inner text?");
|
|
||||||
break;
|
|
||||||
case "RemoveAttribute":
|
case "RemoveAttribute":
|
||||||
this.RemoveAttribute(edit.id, edit.name, edit.ns);
|
this.RemoveAttribute(edit.id, edit.name, edit.ns);
|
||||||
break;
|
break;
|
||||||
@@ -745,8 +710,6 @@ function is_element_node(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function event_bubbles(event) {
|
function event_bubbles(event) {
|
||||||
console.log("event_bubbles", event);
|
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case "copy":
|
case "copy":
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+11
-8
@@ -64,8 +64,9 @@ impl WebsysDom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_template_node(&self, v: &TemplateNode) -> web_sys::Node {
|
fn create_template_node(&self, v: &TemplateNode) -> web_sys::Node {
|
||||||
|
use TemplateNode::*;
|
||||||
match v {
|
match v {
|
||||||
TemplateNode::Element {
|
Element {
|
||||||
tag,
|
tag,
|
||||||
namespace,
|
namespace,
|
||||||
attrs,
|
attrs,
|
||||||
@@ -86,6 +87,12 @@ impl WebsysDom {
|
|||||||
} = attr
|
} = attr
|
||||||
{
|
{
|
||||||
match namespace {
|
match namespace {
|
||||||
|
Some(ns) if *ns == "style" => el
|
||||||
|
.dyn_ref::<HtmlElement>()
|
||||||
|
.unwrap()
|
||||||
|
.style()
|
||||||
|
.set_property(name, value)
|
||||||
|
.unwrap(),
|
||||||
Some(ns) => el.set_attribute_ns(Some(ns), name, value).unwrap(),
|
Some(ns) => el.set_attribute_ns(Some(ns), name, value).unwrap(),
|
||||||
None => el.set_attribute(name, value).unwrap(),
|
None => el.set_attribute(name, value).unwrap(),
|
||||||
}
|
}
|
||||||
@@ -99,9 +106,9 @@ impl WebsysDom {
|
|||||||
el.dyn_into().unwrap()
|
el.dyn_into().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateNode::Text(t) => self.document.create_text_node(t).dyn_into().unwrap(),
|
Text(t) => self.document.create_text_node(t).dyn_into().unwrap(),
|
||||||
TemplateNode::DynamicText(_) => self.document.create_text_node("p").dyn_into().unwrap(),
|
DynamicText(_) => self.document.create_text_node("p").dyn_into().unwrap(),
|
||||||
TemplateNode::Dynamic(_) => {
|
Dynamic(_) => {
|
||||||
let el = self.document.create_element("pre").unwrap();
|
let el = self.document.create_element("pre").unwrap();
|
||||||
el.toggle_attribute("hidden");
|
el.toggle_attribute("hidden");
|
||||||
el.dyn_into().unwrap()
|
el.dyn_into().unwrap()
|
||||||
@@ -112,7 +119,6 @@ impl WebsysDom {
|
|||||||
pub fn apply_edits(&mut self, mut edits: Vec<Mutation>) {
|
pub fn apply_edits(&mut self, mut edits: Vec<Mutation>) {
|
||||||
use Mutation::*;
|
use Mutation::*;
|
||||||
let i = &self.interpreter;
|
let i = &self.interpreter;
|
||||||
|
|
||||||
for edit in edits.drain(..) {
|
for edit in edits.drain(..) {
|
||||||
match edit {
|
match edit {
|
||||||
AssignId { path, id } => i.AssignId(path, id.0 as u32),
|
AssignId { path, id } => i.AssignId(path, id.0 as u32),
|
||||||
@@ -145,9 +151,6 @@ impl WebsysDom {
|
|||||||
RemoveEventListener { name, id } => i.RemoveEventListener(name, id.0 as u32),
|
RemoveEventListener { name, id } => i.RemoveEventListener(name, id.0 as u32),
|
||||||
Remove { id } => i.Remove(id.0 as u32),
|
Remove { id } => i.Remove(id.0 as u32),
|
||||||
PushRoot { id } => i.PushRoot(id.0 as u32),
|
PushRoot { id } => i.PushRoot(id.0 as u32),
|
||||||
// Mutation::RemoveEventListener { root, name: event } => self
|
|
||||||
// .interpreter
|
|
||||||
// .RemoveEventListener(root, event, event_bubbles(event)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
|||||||
|
|
||||||
websys_dom.load_templates(&edits.templates);
|
websys_dom.load_templates(&edits.templates);
|
||||||
websys_dom.apply_edits(edits.edits);
|
websys_dom.apply_edits(edits.edits);
|
||||||
|
|
||||||
|
// the mutations come back with nothing - we need to actually mount them
|
||||||
websys_dom.mount();
|
websys_dom.mount();
|
||||||
|
|
||||||
let mut work_loop = ric_raf::RafLoop::new();
|
let mut work_loop = ric_raf::RafLoop::new();
|
||||||
@@ -243,7 +245,6 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
|||||||
let deadline = work_loop.wait_for_idle_time().await;
|
let deadline = work_loop.wait_for_idle_time().await;
|
||||||
|
|
||||||
// run the virtualdom work phase until the frame deadline is reached
|
// run the virtualdom work phase until the frame deadline is reached
|
||||||
// let deadline = gloo_timers::future::sleep(Duration::from_millis(10000));
|
|
||||||
let edits = dom.render_with_deadline(deadline).await;
|
let edits = dom.render_with_deadline(deadline).await;
|
||||||
|
|
||||||
// wait for the animation frame to fire so we can apply our changes
|
// wait for the animation frame to fire so we can apply our changes
|
||||||
|
|||||||
Reference in new issue
Block a user