wip: reduce warnings
This commit is contained in:
1 parent
12afd2b0f2
commit
0ded32e184
7 files changed
+119
-124
No files matched your search
@@ -62,10 +62,6 @@ impl<'bump> DiffStack<'bump> {
|
|||||||
self.scope_stack.pop();
|
self.scope_stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_scope(&mut self) -> Option<ScopeId> {
|
|
||||||
self.scope_stack.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push(&mut self, instruction: DiffInstruction<'bump>) {
|
pub fn push(&mut self, instruction: DiffInstruction<'bump>) {
|
||||||
self.instructions.push(instruction)
|
self.instructions.push(instruction)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,18 @@
|
|||||||
//!
|
//!
|
||||||
//! 3rd party renderers are responsible for converting their native events into these virtual event types. Events might
|
//! 3rd party renderers are responsible for converting their native events into these virtual event types. Events might
|
||||||
//! be heavy or need to interact through FFI, so the events themselves are designed to be lazy.
|
//! be heavy or need to interact through FFI, so the events themselves are designed to be lazy.
|
||||||
use crate::innerlude::{ElementId, ScopeId};
|
|
||||||
|
|
||||||
use bumpalo::boxed::Box as BumpBox;
|
|
||||||
use std::{any::Any, cell::RefCell, fmt::Debug, ops::Deref, rc::Rc};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
innerlude::NodeFactory,
|
innerlude::Listener,
|
||||||
innerlude::{Attribute, Listener, VNode},
|
innerlude::{ElementId, NodeFactory, ScopeId},
|
||||||
|
};
|
||||||
|
use bumpalo::boxed::Box as BumpBox;
|
||||||
|
use std::{
|
||||||
|
any::Any,
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
fmt::Debug,
|
||||||
|
ops::Deref,
|
||||||
|
rc::Rc,
|
||||||
};
|
};
|
||||||
use std::cell::Cell;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UserEvent {
|
pub struct UserEvent {
|
||||||
@@ -832,7 +834,7 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the raw code
|
// get the raw code
|
||||||
fn raw_code(&self) -> u32 {
|
pub fn raw_code(&self) -> u32 {
|
||||||
*self as u32
|
*self as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ pub mod scheduler;
|
|||||||
pub mod scope;
|
pub mod scope;
|
||||||
pub mod test_dom;
|
pub mod test_dom;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub mod vdomdisplay;
|
|
||||||
pub mod virtual_dom;
|
pub mod virtual_dom;
|
||||||
|
|
||||||
pub(crate) mod innerlude {
|
pub(crate) mod innerlude {
|
||||||
|
|||||||
@@ -328,3 +328,110 @@ impl Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// render the scope to a string using the rsx! syntax
|
||||||
|
pub(crate) struct ScopeRenderer<'a> {
|
||||||
|
pub skip_components: bool,
|
||||||
|
pub show_fragments: bool,
|
||||||
|
pub _scope: &'a Scope,
|
||||||
|
pub _pre_render: bool,
|
||||||
|
pub _newline: bool,
|
||||||
|
pub _indent: bool,
|
||||||
|
pub _max_depth: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is more or less a debug tool, but it'll render the entire tree to the terminal
|
||||||
|
impl<'a> ScopeRenderer<'a> {
|
||||||
|
pub fn render(
|
||||||
|
&self,
|
||||||
|
vdom: &VirtualDom,
|
||||||
|
node: &VNode,
|
||||||
|
f: &mut std::fmt::Formatter,
|
||||||
|
il: u16,
|
||||||
|
) -> std::fmt::Result {
|
||||||
|
const INDENT: &str = " ";
|
||||||
|
let write_indent = |_f: &mut std::fmt::Formatter, le| {
|
||||||
|
for _ in 0..le {
|
||||||
|
write!(_f, "{}", INDENT).unwrap();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match &node {
|
||||||
|
VNode::Text(text) => {
|
||||||
|
write_indent(f, il);
|
||||||
|
write!(f, "\"{}\"\n", text.text)?
|
||||||
|
}
|
||||||
|
VNode::Anchor(anchor) => {
|
||||||
|
write_indent(f, il);
|
||||||
|
write!(f, "Anchor {{}}\n")?;
|
||||||
|
}
|
||||||
|
VNode::Element(el) => {
|
||||||
|
write_indent(f, il);
|
||||||
|
write!(f, "{} {{\n", el.tag_name)?;
|
||||||
|
// write!(f, "element: {}", el.tag_name)?;
|
||||||
|
let mut attr_iter = el.attributes.iter().peekable();
|
||||||
|
|
||||||
|
while let Some(attr) = attr_iter.next() {
|
||||||
|
match attr.namespace {
|
||||||
|
None => {
|
||||||
|
//
|
||||||
|
write_indent(f, il + 1);
|
||||||
|
write!(f, "{}: \"{}\"\n", attr.name, attr.value)?
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(ns) => {
|
||||||
|
// write the opening tag
|
||||||
|
write_indent(f, il + 1);
|
||||||
|
write!(f, " {}:\"", ns)?;
|
||||||
|
let mut cur_ns_el = attr;
|
||||||
|
'ns_parse: loop {
|
||||||
|
write!(f, "{}:{};", cur_ns_el.name, cur_ns_el.value)?;
|
||||||
|
match attr_iter.peek() {
|
||||||
|
Some(next_attr) if next_attr.namespace == Some(ns) => {
|
||||||
|
cur_ns_el = attr_iter.next().unwrap();
|
||||||
|
}
|
||||||
|
_ => break 'ns_parse,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// write the closing tag
|
||||||
|
write!(f, "\"")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for child in el.children {
|
||||||
|
self.render(vdom, child, f, il + 1)?;
|
||||||
|
}
|
||||||
|
write_indent(f, il);
|
||||||
|
|
||||||
|
write!(f, "}}\n")?;
|
||||||
|
}
|
||||||
|
VNode::Fragment(frag) => {
|
||||||
|
if self.show_fragments {
|
||||||
|
write_indent(f, il);
|
||||||
|
write!(f, "Fragment {{\n")?;
|
||||||
|
for child in frag.children {
|
||||||
|
self.render(vdom, child, f, il + 1)?;
|
||||||
|
}
|
||||||
|
write_indent(f, il);
|
||||||
|
write!(f, "}}\n")?;
|
||||||
|
} else {
|
||||||
|
for child in frag.children {
|
||||||
|
self.render(vdom, child, f, il)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VNode::Component(vcomp) => {
|
||||||
|
let idx = vcomp.associated_scope.get().unwrap();
|
||||||
|
if !self.skip_components {
|
||||||
|
let new_node = vdom.get_scope(idx).unwrap().root_node();
|
||||||
|
self.render(vdom, new_node, f, il)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VNode::Suspended { .. } => {
|
||||||
|
// we can't do anything with suspended nodes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ pub struct TestDom {
|
|||||||
impl TestDom {
|
impl TestDom {
|
||||||
pub fn new() -> TestDom {
|
pub fn new() -> TestDom {
|
||||||
let bump = Bump::new();
|
let bump = Bump::new();
|
||||||
let mut scheduler = Scheduler::new();
|
let scheduler = Scheduler::new();
|
||||||
TestDom { bump, scheduler }
|
TestDom { bump, scheduler }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
use crate::innerlude::*;
|
|
||||||
|
|
||||||
pub(crate) struct ScopeRenderer<'a> {
|
|
||||||
pub skip_components: bool,
|
|
||||||
pub show_fragments: bool,
|
|
||||||
pub _scope: &'a Scope,
|
|
||||||
pub _pre_render: bool,
|
|
||||||
pub _newline: bool,
|
|
||||||
pub _indent: bool,
|
|
||||||
pub _max_depth: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is more or less a debug tool, but it'll render the entire tree to the terminal
|
|
||||||
impl<'a> ScopeRenderer<'a> {
|
|
||||||
pub fn render(
|
|
||||||
&self,
|
|
||||||
vdom: &VirtualDom,
|
|
||||||
node: &VNode,
|
|
||||||
f: &mut std::fmt::Formatter,
|
|
||||||
il: u16,
|
|
||||||
) -> std::fmt::Result {
|
|
||||||
const INDENT: &str = " ";
|
|
||||||
let write_indent = |_f: &mut std::fmt::Formatter, le| {
|
|
||||||
for _ in 0..le {
|
|
||||||
write!(_f, "{}", INDENT).unwrap();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match &node {
|
|
||||||
VNode::Text(text) => {
|
|
||||||
write_indent(f, il);
|
|
||||||
write!(f, "\"{}\"\n", text.text)?
|
|
||||||
}
|
|
||||||
VNode::Anchor(anchor) => {
|
|
||||||
write_indent(f, il);
|
|
||||||
write!(f, "Anchor {{}}\n")?;
|
|
||||||
}
|
|
||||||
VNode::Element(el) => {
|
|
||||||
write_indent(f, il);
|
|
||||||
write!(f, "{} {{\n", el.tag_name)?;
|
|
||||||
// write!(f, "element: {}", el.tag_name)?;
|
|
||||||
let mut attr_iter = el.attributes.iter().peekable();
|
|
||||||
|
|
||||||
while let Some(attr) = attr_iter.next() {
|
|
||||||
match attr.namespace {
|
|
||||||
None => {
|
|
||||||
//
|
|
||||||
write_indent(f, il + 1);
|
|
||||||
write!(f, "{}: \"{}\"\n", attr.name, attr.value)?
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(ns) => {
|
|
||||||
// write the opening tag
|
|
||||||
write_indent(f, il + 1);
|
|
||||||
write!(f, " {}:\"", ns)?;
|
|
||||||
let mut cur_ns_el = attr;
|
|
||||||
'ns_parse: loop {
|
|
||||||
write!(f, "{}:{};", cur_ns_el.name, cur_ns_el.value)?;
|
|
||||||
match attr_iter.peek() {
|
|
||||||
Some(next_attr) if next_attr.namespace == Some(ns) => {
|
|
||||||
cur_ns_el = attr_iter.next().unwrap();
|
|
||||||
}
|
|
||||||
_ => break 'ns_parse,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// write the closing tag
|
|
||||||
write!(f, "\"")?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for child in el.children {
|
|
||||||
self.render(vdom, child, f, il + 1)?;
|
|
||||||
}
|
|
||||||
write_indent(f, il);
|
|
||||||
|
|
||||||
write!(f, "}}\n")?;
|
|
||||||
}
|
|
||||||
VNode::Fragment(frag) => {
|
|
||||||
if self.show_fragments {
|
|
||||||
write_indent(f, il);
|
|
||||||
write!(f, "Fragment {{\n")?;
|
|
||||||
for child in frag.children {
|
|
||||||
self.render(vdom, child, f, il + 1)?;
|
|
||||||
}
|
|
||||||
write_indent(f, il);
|
|
||||||
write!(f, "}}\n")?;
|
|
||||||
} else {
|
|
||||||
for child in frag.children {
|
|
||||||
self.render(vdom, child, f, il)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VNode::Component(vcomp) => {
|
|
||||||
let idx = vcomp.associated_scope.get().unwrap();
|
|
||||||
if !self.skip_components {
|
|
||||||
let new_node = vdom.get_scope(idx).unwrap().root_node();
|
|
||||||
self.render(vdom, new_node, f, il)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VNode::Suspended { .. } => {
|
|
||||||
// we can't do anything with suspended nodes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -362,8 +362,6 @@ impl std::fmt::Display for VirtualDom {
|
|||||||
let base = self.base_scope();
|
let base = self.base_scope();
|
||||||
let root = base.root_node();
|
let root = base.root_node();
|
||||||
|
|
||||||
use crate::vdomdisplay::ScopeRenderer;
|
|
||||||
|
|
||||||
let renderer = ScopeRenderer {
|
let renderer = ScopeRenderer {
|
||||||
show_fragments: false,
|
show_fragments: false,
|
||||||
skip_components: false,
|
skip_components: false,
|
||||||
|
|||||||
Reference in new issue
Block a user