feat: move over to push based mechanism

This commit is contained in:
Jonathan Kelley committed 2021-07-14 17:39:26 -04:00
1 parent e7238762ae
commit 80e6c25698
7 files changed
+96 -70

No files matched your search

+1 -2
View File
@@ -305,8 +305,7 @@ Any function prefixed with "use" should not be called conditionally.
) -> (&TaskHandle, &mut Option<Out>)
where
Out: 'static,
Fut: Future<Output = Out>,
Fut: 'static,
Fut: Future<Output = Out> + 'static,
Init: FnOnce() -> Fut + 'src,
{
struct TaskHook<T> {
+8 -8
View File
@@ -66,8 +66,8 @@ use std::any::Any;
/// target-specific Node type as well as easily serializing the edits to be sent over a network or IPC connection.
pub trait RealDom<'a> {
fn request_available_node(&mut self) -> RealDomNode;
// node ref
fn raw_node_as_any_mut(&self) -> &mut dyn Any;
fn raw_node_as_any(&self) -> &mut dyn Any;
}
pub struct DomEditor<'real, 'bump> {
@@ -77,7 +77,7 @@ use DomEdit::*;
impl<'real, 'bump> DomEditor<'real, 'bump> {
// Navigation
pub(crate) fn push(&mut self, root: RealDomNode) {
self.edits.push(PushRoot { root: root.0 });
self.edits.push(PushRoot { root });
}
pub(crate) fn pop(&mut self) {
self.edits.push(PopRoot {});
@@ -105,7 +105,7 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
// Create
pub(crate) fn create_text_node(&mut self, text: &'bump str, id: RealDomNode) {
self.edits.push(CreateTextNode { text, id: id.0 });
self.edits.push(CreateTextNode { text, id });
}
pub(crate) fn create_element(
&mut self,
@@ -114,14 +114,14 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
id: RealDomNode,
) {
match ns {
Some(ns) => self.edits.push(CreateElementNs { id: id.0, ns, tag }),
None => self.edits.push(CreateElement { id: id.0, tag }),
Some(ns) => self.edits.push(CreateElementNs { id, ns, tag }),
None => self.edits.push(CreateElement { id, tag }),
}
}
// placeholders are nodes that don't get rendered but still exist as an "anchor" in the real dom
pub(crate) fn create_placeholder(&mut self, id: RealDomNode) {
self.edits.push(CreatePlaceholder { id: id.0 });
self.edits.push(CreatePlaceholder { id });
}
// events
@@ -136,7 +136,7 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
scope,
event,
idx: element_id,
node: realnode.0,
node: realnode,
});
}
pub(crate) fn remove_event_listener(&mut self, event: &'static str) {
+12 -12
View File
@@ -7,7 +7,7 @@
//!
//!
use crate::innerlude::ScopeIdx;
use crate::{innerlude::ScopeIdx, RealDomNode};
use serde::{Deserialize, Serialize};
/// A `DomEdit` represents a serialzied form of the VirtualDom's trait-based API. This allows streaming edits across the
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "type")]
pub enum DomEdit<'bump> {
PushRoot {
root: u64,
root: RealDomNode,
},
PopRoot,
AppendChildren {
@@ -29,38 +29,38 @@ pub enum DomEdit<'bump> {
RemoveAllChildren,
CreateTextNode {
text: &'bump str,
id: u64,
id: RealDomNode,
},
CreateElement {
tag: &'bump str,
id: u64,
id: RealDomNode,
},
CreateElementNs {
tag: &'bump str,
id: u64,
ns: &'bump str,
id: RealDomNode,
ns: &'static str,
},
CreatePlaceholder {
id: u64,
id: RealDomNode,
},
NewEventListener {
event: &'bump str,
event: &'static str,
scope: ScopeIdx,
node: u64,
node: RealDomNode,
idx: usize,
},
RemoveEventListener {
event: &'bump str,
event: &'static str,
},
SetText {
text: &'bump str,
},
SetAttribute {
field: &'bump str,
field: &'static str,
value: &'bump str,
ns: Option<&'bump str>,
},
RemoveAttribute {
name: &'bump str,
name: &'static str,
},
}
+10 -8
View File
@@ -4,6 +4,7 @@ use std::{
};
use futures_util::StreamExt;
use slotmap::{DefaultKey, KeyData};
use crate::innerlude::*;
@@ -55,16 +56,17 @@ impl PartialOrd for HeightMarker {
/// "u64" was chosen for two reasons
/// - 0 cost hashing
/// - use with slotmap and other versioned slot arenas
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RealDomNode(pub u64);
pub struct RealDomNode(pub DefaultKey);
impl RealDomNode {
pub fn new(id: u64) -> Self {
Self(id)
pub fn empty() -> Self {
let data = KeyData::from_ffi(u64::MIN);
let key: DefaultKey = data.into();
Self(key)
}
pub const fn empty() -> Self {
Self(u64::MIN)
}
pub const fn empty_cell() -> Cell<Self> {
pub fn empty_cell() -> Cell<Self> {
Cell::new(Self::empty())
}
}
@@ -88,7 +90,7 @@ impl DebugDom {
}
}
impl<'a> RealDom<'a> for DebugDom {
fn raw_node_as_any_mut(&self) -> &mut dyn std::any::Any {
fn raw_node_as_any(&self) -> &mut dyn std::any::Any {
todo!()
}