refactor insert_before_this to find parent lazily, and use it for rebuilding reactive components by replacing their whole contents

This commit is contained in:
Greg Johnston 2024-06-15 10:38:15 -04:00
parent 1cf3b3dc66
commit e44ecb5cde
29 changed files with 196 additions and 306 deletions

View file

@ -56,9 +56,7 @@ impl Mountable<LeptosGtk> for Element {
.insert_before(&parent.0, marker.as_ref().map(|m| &m.0));
}
fn insert_before_this(
&self,
parent: &<LeptosGtk as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<LeptosGtk>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
@ -81,9 +79,7 @@ impl Mountable<LeptosGtk> for Text {
.insert_before(&parent.0, marker.as_ref().map(|m| &m.0));
}
fn insert_before_this(
&self,
parent: &<LeptosGtk as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<LeptosGtk>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
@ -341,9 +337,7 @@ where
LeptosGtk::insert_node(parent, &self.widget, marker);
}
fn insert_before_this(
&self,
parent: &<LeptosGtk as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<LeptosGtk>,
) -> bool {
child.mount(parent, Some(self.widget.as_ref()));

View file

@ -139,15 +139,11 @@ where
self.placeholder.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &Rndr::Element,
child: &mut dyn Mountable<Rndr>,
) -> bool {
fn insert_before_this(&self, child: &mut dyn Mountable<Rndr>) -> bool {
if self.showing_fallback {
self.fallback.insert_before_this(parent, child)
self.fallback.insert_before_this(child)
} else {
self.children.insert_before_this(parent, child)
self.children.insert_before_this(child)
}
}
}
@ -203,7 +199,12 @@ where
)
}
fn rebuild(self, _state: &mut Self::State) {}
fn rebuild(self, state: &mut Self::State) {
let new = self.build();
let mut old = std::mem::replace(state, new);
old.insert_before_this(state);
old.unmount();
}
}
impl<Chil, Fal, Rndr> AddAnyAttr<Rndr> for ErrorBoundaryView<Chil, Fal, Rndr>

View file

@ -22,7 +22,7 @@ use tachys::{
view::{
add_attr::AddAnyAttr,
either::{EitherKeepAlive, EitherKeepAliveState},
Position, PositionState, Render, RenderHtml,
Mountable, Position, PositionState, Render, RenderHtml,
},
};
use throw_error::ErrorHookFuture;
@ -101,7 +101,12 @@ where
)
}
fn rebuild(self, _state: &mut Self::State) {}
fn rebuild(self, state: &mut Self::State) {
let new = self.build();
let mut old = std::mem::replace(state, new);
old.insert_before_this(state);
old.unmount();
}
}
impl<const TRANSITION: bool, Fal, Chil, Rndr> AddAnyAttr<Rndr>

View file

@ -161,11 +161,7 @@ impl Mountable<Dom> for BodyViewState {
) {
}
fn insert_before_this(
&self,
_parent: &<Dom as Renderer>::Element,
_child: &mut dyn Mountable<Dom>,
) -> bool {
fn insert_before_this(&self, _child: &mut dyn Mountable<Dom>) -> bool {
true
}
}

View file

@ -181,11 +181,7 @@ impl Mountable<Dom> for HtmlViewState {
// the <html> tag doesn't need to be mounted anywhere, of course
}
fn insert_before_this(
&self,
_parent: &<Dom as Renderer>::Element,
_child: &mut dyn Mountable<Dom>,
) -> bool {
fn insert_before_this(&self, _child: &mut dyn Mountable<Dom>) -> bool {
true
}
}

View file

@ -428,7 +428,7 @@ where
fn mount(
&mut self,
_parent: &<Dom as Renderer>::Element,
_marker: Option<&<Dom as Renderer>::Node>,
marker: Option<&<Dom as Renderer>::Node>,
) {
// we always mount this to the <head>, which is the whole point
// but this shouldn't warn about the parent being a regular element or being unused
@ -437,12 +437,8 @@ where
self.state.mount(&document_head(), None);
}
fn insert_before_this(
&self,
_parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
self.state.insert_before_this(&document_head(), child)
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
self.state.insert_before_this(child)
}
}

View file

@ -291,11 +291,7 @@ impl Mountable<Dom> for TitleViewState {
// TitleView::el() guarantees that there is a <title> in the <head>
}
fn insert_before_this(
&self,
_parent: &<Dom as Renderer>::Element,
_child: &mut dyn Mountable<Dom>,
) -> bool {
fn insert_before_this(&self, _child: &mut dyn Mountable<Dom>) -> bool {
true
}
}

View file

@ -162,12 +162,10 @@ where
self.view.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.view.insert_before_this(parent, child)
self.view.insert_before_this(child)
}
}

View file

@ -730,12 +730,10 @@ where
self.view.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &R::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.view.insert_before_this(parent, child)
self.view.insert_before_this(child)
}
}

View file

@ -209,12 +209,10 @@ where
self.inner.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
self.inner.insert_before_this(parent, child)
self.inner.insert_before_this(child)
}
}
@ -408,11 +406,9 @@ where
self.view_state.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.view_state.insert_before_this(parent, child)
self.view_state.insert_before_this(child)
}
}

View file

@ -805,16 +805,14 @@ where
self.inner.write().or_poisoned().state.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
/*self.inner
.write()
.or_poisoned()
.state
.insert_before_this(parent, child)*/
.insert_before_this(child)*/
todo!()
}
}
@ -1030,12 +1028,10 @@ where
self.view.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &R::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.view.insert_before_this(parent, child)
self.view.insert_before_this(child)
}
}

View file

@ -446,13 +446,14 @@ where
R::insert_node(parent, self.el.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.el.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
if let Some(parent) = R::get_parent(self.el.as_ref()) {
if let Some(element) = R::Element::cast_from(parent) {
child.mount(&element, Some(self.el.as_ref()));
return true;
}
}
false
}
}

View file

@ -92,13 +92,8 @@ impl<R: Renderer> Mountable<R> for OcoStrState<R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}

View file

@ -46,9 +46,7 @@ macro_rules! render_primitive {
R::insert_node(parent, self.0.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.0.as_ref()));
@ -318,9 +316,7 @@ impl<R: Renderer> Mountable<R> for ReadGuardStringState<R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));

View file

@ -65,8 +65,11 @@ where
}
#[track_caller]
fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild
fn rebuild(self, state: &mut Self::State) {
let new = self.build();
let mut old = std::mem::replace(state, new);
old.insert_before_this(state);
old.unmount();
}
}
pub struct RenderEffectState<T: 'static>(Option<RenderEffect<T>>);
@ -94,13 +97,9 @@ where
}
}
fn insert_before_this(
&self,
parent: &R::Element,
child: &mut dyn Mountable<R>,
) -> bool {
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
if let Some(inner) = &self.0 {
inner.insert_before_this(parent, child)
inner.insert_before_this(child)
} else {
false
}
@ -132,13 +131,9 @@ where
}
}
fn insert_before_this(
&self,
parent: &R::Element,
child: &mut dyn Mountable<R>,
) -> bool {
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
if let Some(inner) = &self.effect {
inner.insert_before_this(parent, child)
inner.insert_before_this(child)
} else {
false
}
@ -245,12 +240,8 @@ where
});
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
self.with_value_mut(|value| value.insert_before_this(parent, child))
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.with_value_mut(|value| value.insert_before_this(child))
.unwrap_or(false)
}
}
@ -276,13 +267,9 @@ where
}
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
if let Ok(inner) = &self {
inner.insert_before_this(parent, child)
inner.insert_before_this(child)
} else {
false
}
@ -414,7 +401,8 @@ mod stable {
renderer::Renderer,
ssr::StreamBuilder,
view::{
add_attr::AddAnyAttr, Position, PositionState, Render, RenderHtml,
add_attr::AddAnyAttr, Mountable, Position, PositionState, Render,
RenderHtml,
},
};
use reactive_graph::{
@ -441,8 +429,11 @@ mod stable {
}
#[track_caller]
fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild
fn rebuild(self, state: &mut Self::State) {
let new = self.build();
let mut old = std::mem::replace(state, new);
old.insert_before_this(state);
old.unmount();
}
}
@ -585,8 +576,11 @@ mod stable {
}
#[track_caller]
fn rebuild(self, _state: &mut Self::State) {
// TODO rebuild
fn rebuild(self, state: &mut Self::State) {
let new = self.build();
let mut old = std::mem::replace(state, new);
old.insert_before_this(state);
old.unmount();
}
}

View file

@ -179,11 +179,9 @@ where
self.state.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.state.insert_before_this(parent, child)
self.state.insert_before_this(child)
}
}

View file

@ -64,12 +64,10 @@ where
self.inner.borrow_mut().mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &Rndr::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
self.inner.borrow_mut().insert_before_this(parent, child)
self.inner.borrow_mut().insert_before_this(child)
}
}

View file

@ -349,13 +349,14 @@ impl Mountable<Dom> for Node {
Dom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
child.mount(parent, Some(self));
true
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
let parent =
Dom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self));
return true;
}
false
}
}
@ -368,13 +369,14 @@ impl Mountable<Dom> for Text {
Dom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
let parent =
Dom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self));
return true;
}
false
}
}
@ -387,13 +389,14 @@ impl Mountable<Dom> for Comment {
Dom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
let parent =
Dom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self));
return true;
}
false
}
}
@ -406,13 +409,14 @@ impl Mountable<Dom> for Element {
Dom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
let parent =
Dom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self));
return true;
}
false
}
}
@ -425,13 +429,14 @@ impl Mountable<Dom> for DocumentFragment {
Dom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<Dom as Renderer>::Element,
child: &mut dyn Mountable<Dom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<Dom>) -> bool {
let parent =
Dom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self));
return true;
}
false
}
}

View file

@ -319,13 +319,14 @@ impl Mountable<MockDom> for Node {
MockDom::insert_node(parent, self, marker);
}
fn insert_before_this(
&self,
parent: &<MockDom as Renderer>::Element,
child: &mut dyn Mountable<MockDom>,
) -> bool {
child.mount(parent, Some(self));
true
fn insert_before_this(&self, child: &mut dyn Mountable<MockDom>) -> bool {
let parent =
MockDom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self.as_ref()));
return true;
}
false
}
}
@ -338,13 +339,14 @@ impl Mountable<MockDom> for Text {
MockDom::insert_node(parent, self.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<MockDom as Renderer>::Element,
child: &mut dyn Mountable<MockDom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<MockDom>) -> bool {
let parent =
MockDom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self.as_ref()));
return true;
}
false
}
}
@ -357,13 +359,14 @@ impl Mountable<MockDom> for Element {
MockDom::insert_node(parent, self.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<MockDom as Renderer>::Element,
child: &mut dyn Mountable<MockDom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<MockDom>) -> bool {
let parent =
MockDom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self.as_ref()));
return true;
}
false
}
}
@ -376,13 +379,14 @@ impl Mountable<MockDom> for Placeholder {
MockDom::insert_node(parent, self.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<MockDom as Renderer>::Element,
child: &mut dyn Mountable<MockDom>,
) -> bool {
child.mount(parent, Some(self.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<MockDom>) -> bool {
let parent =
MockDom::get_parent(self.as_ref()).and_then(Element::cast_from);
if let Some(parent) = parent {
child.mount(&parent, Some(self.as_ref()));
return true;
}
false
}
}

View file

@ -571,10 +571,8 @@ impl Mountable<Sledgehammer> for SNode {
fn insert_before_this(
&self,
parent: &SNode,
child: &mut dyn Mountable<Sledgehammer>,
_child: &mut dyn Mountable<Sledgehammer>,
) -> bool {
child.mount(parent, Some(self));
true
todo!()
}
}

View file

@ -56,8 +56,7 @@ where
state: Box<dyn Any>,
unmount: fn(&mut dyn Any),
mount: fn(&mut dyn Any, parent: &R::Element, marker: Option<&R::Node>),
insert_before_this:
fn(&dyn Any, parent: &R::Element, child: &mut dyn Mountable<R>) -> bool,
insert_before_this: fn(&dyn Any, child: &mut dyn Mountable<R>) -> bool,
rndr: PhantomData<R>,
}
@ -113,7 +112,6 @@ where
fn insert_before_this<R, T>(
state: &dyn Any,
parent: &R::Element,
child: &mut dyn Mountable<R>,
) -> bool
where
@ -124,7 +122,7 @@ where
let state = state
.downcast_ref::<T::State>()
.expect("AnyViewState::opening_node couldn't downcast state");
state.insert_before_this(parent, child)
state.insert_before_this(child)
}
impl<T, R> IntoAny<R> for T
@ -417,12 +415,8 @@ where
(self.mount)(&mut *self.state, parent, marker)
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
(self.insert_before_this)(self, parent, child)
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
(self.insert_before_this)(self, child)
}
}
/*

View file

@ -91,14 +91,12 @@ where
}
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
match &self.state {
Either::Left(left) => left.insert_before_this(parent, child),
Either::Right(right) => right.insert_before_this(parent, child),
Either::Left(left) => left.insert_before_this(child),
Either::Right(right) => right.insert_before_this(child),
}
}
}
@ -415,21 +413,19 @@ where
self.marker.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
if self.showing_b {
self.b
.as_ref()
.expect("B was not present")
.insert_before_this(parent, child)
.insert_before_this(child)
} else {
self.a
.as_ref()
.expect("A was no present")
.insert_before_this(parent, child)
.insert_before_this(child)
}
}
}
@ -469,13 +465,11 @@ macro_rules! tuples {
};
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
match &self.state {
$([<EitherOf $num>]::$ty(this) =>this.insert_before_this(parent, child),)*
$([<EitherOf $num>]::$ty(this) =>this.insert_before_this(child),)*
}
}
}

View file

@ -95,20 +95,14 @@ where
}
}
fn insert_before_this(
&self,
parent: &R::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
if self
.state
.as_ref()
.map(|n| n.insert_before_this(parent, child))
== Ok(true)
if self.state.as_ref().map(|n| n.insert_before_this(child)) == Ok(true)
{
true
} else {
self.placeholder.insert_before_this(parent, child)
self.placeholder.insert_before_this(child)
}
}
}

View file

@ -163,20 +163,15 @@ where
self.placeholder.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &R::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
if self
.state
.as_ref()
.map(|n| n.insert_before_this(parent, child))
if self.state.as_ref().map(|n| n.insert_before_this(child))
== Some(true)
{
true
} else {
self.placeholder.insert_before_this(parent, child)
self.placeholder.insert_before_this(child)
}
}
}
@ -269,13 +264,11 @@ where
self.marker.mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
if let Some(first) = self.states.first() {
first.insert_before_this(parent, child)
first.insert_before_this(child)
} else {
false
}

View file

@ -289,14 +289,10 @@ where
}
}
fn insert_before_this(
&self,
parent: &<Rndr as Renderer>::Element,
child: &mut dyn Mountable<Rndr>,
) -> bool {
fn insert_before_this(&self, child: &mut dyn Mountable<Rndr>) -> bool {
self.rendered_items
.first()
.map(|n| n.insert_before_this(parent, child))
.map(|n| n.insert_before_this(child))
.unwrap_or(false)
}
}

View file

@ -200,11 +200,7 @@ pub trait Mountable<R: Renderer> {
/// Inserts another `Mountable` type before this one. Returns `false` if
/// this does not actually exist in the UI (for example, `()`).
fn insert_before_this(
&self,
parent: &R::Element,
child: &mut dyn Mountable<R>,
) -> bool;
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool;
/// Inserts another `Mountable` type before this one, or before the marker
/// if this one doesn't exist in the UI (for example, `()`).
@ -214,7 +210,7 @@ pub trait Mountable<R: Renderer> {
child: &mut dyn Mountable<R>,
marker: Option<&R::Node>,
) {
if !self.insert_before_this(parent, child) {
if !self.insert_before_this(child) {
child.mount(parent, marker);
}
}
@ -248,13 +244,11 @@ where
}
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.as_ref()
.map(|inner| inner.insert_before_this(parent, child))
.map(|inner| inner.insert_before_this(child))
.unwrap_or(false)
}
}
@ -272,12 +266,10 @@ where
self.borrow_mut().mount(parent, marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
self.borrow().insert_before_this(parent, child)
self.borrow().insert_before_this(child)
}
}

View file

@ -35,13 +35,10 @@ macro_rules! render_primitive {
R::insert_node(parent, self.0.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.0.as_ref()));
true
self.0.insert_before_this(child)
}
}

View file

@ -129,13 +129,8 @@ where
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}
@ -222,13 +217,8 @@ impl<R: Renderer> Mountable<R> for StringState<R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}
@ -318,13 +308,8 @@ impl<R: Renderer> Mountable<R> for RcStrState<R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}
@ -413,13 +398,8 @@ impl<R: Renderer> Mountable<R> for ArcStrState<R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}
@ -508,12 +488,7 @@ impl<'a, R: Renderer> Mountable<R> for CowStrState<'a, R> {
R::insert_node(parent, self.node.as_ref(), marker);
}
fn insert_before_this(
&self,
parent: &<R as Renderer>::Element,
child: &mut dyn Mountable<R>,
) -> bool {
child.mount(parent, Some(self.node.as_ref()));
true
fn insert_before_this(&self, child: &mut dyn Mountable<R>) -> bool {
self.node.insert_before_this(child)
}
}

View file

@ -63,11 +63,7 @@ impl<R: Renderer> Mountable<R> for () {
fn mount(&mut self, _parent: &R::Element, _marker: Option<&R::Node>) {}
fn insert_before_this(
&self,
_parent: &<R as Renderer>::Element,
_child: &mut dyn Mountable<R>,
) -> bool {
fn insert_before_this(&self, _child: &mut dyn Mountable<R>) -> bool {
false
}
}
@ -312,15 +308,13 @@ macro_rules! impl_view_for_tuples {
$($ty.mount(parent, marker));*
}
fn insert_before_this(
&self,
parent: &Rndr::Element,
fn insert_before_this(&self,
child: &mut dyn Mountable<Rndr>,
) -> bool {
#[allow(non_snake_case)] // better macro performance
let ($first, $($ty,)*) = self;
$first.insert_before_this(parent, child)
$(|| $ty.insert_before_this(parent, child))*
$first.insert_before_this(child)
$(|| $ty.insert_before_this(child))*
}
}