Skip to content

Commit 7be5066

Browse files
committed
feat!: memo
1 parent e2a664a commit 7be5066

File tree

16 files changed

+927
-679
lines changed

16 files changed

+927
-679
lines changed

packages/frender-csr/src/render_state/compound.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::pin::Pin;
22

3+
use frender_common::csr::StateUnmount;
4+
35
use crate::RenderState;
46

57
pin_project_lite::pin_project!(
6-
#[derive(Debug, Default)]
8+
#[derive(Debug)]
79
pub struct CompoundState<S, T> {
810
#[pin]
911
pub reactive: S,
@@ -21,6 +23,12 @@ impl<S, T> CompoundState<S, T> {
2123
}
2224
}
2325

26+
impl<S: StateUnmount, T> StateUnmount for CompoundState<S, T> {
27+
fn state_unmount(self: Pin<&mut Self>) {
28+
self.project().reactive.state_unmount()
29+
}
30+
}
31+
2432
impl<R: ?Sized, S: RenderState<R>, T> RenderState<R> for CompoundState<S, T> {
2533
fn unmount(self: Pin<&mut Self>, renderer: &mut R) {
2634
self.project().reactive.unmount(renderer)

packages/frender-html/src/element.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ macro_rules! proxy_csr_element {
138138
$expr.pinned_render_init(renderer)
139139
}
140140

141+
$crate::proxy_csr_element_without_pinned_render_init!(|$this| $expr);
142+
};
143+
}
144+
145+
#[macro_export]
146+
macro_rules! proxy_csr_element_without_pinned_render_init {
147+
(|$this:pat_param| $expr:expr) => {
141148
fn pinned_render_init_by_reusing<Ctx: ?Sized + $crate::HtmlRenderContext>(
142149
self,
143150
render_context: &mut Ctx,

packages/frender-html/src/ui_handles/cursor_placeholders_surrounded.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,31 @@ impl<C, UH> CursorPlaceholdersSurrounded<C, UH> {
112112
out
113113
}
114114

115-
pub fn mount_and_map<R: ?Sized + RenderWithContext, Out, MUH>(
115+
pub fn mount_and_map<R: ?Sized + RenderWithContext, MUH>(
116+
//
117+
self,
118+
render_context: &mut R::RenderContext<'_>,
119+
f: impl FnOnce(UH, &mut R::RenderContext<'_>) -> MUH,
120+
) -> CursorPlaceholdersSurrounded<C::Mounted, MUH>
121+
where
122+
C: UnmountedUiHandle<R>,
123+
{
124+
let Self {
125+
cursor_placeholders: [start, end],
126+
ui_handle,
127+
} = self;
128+
129+
let start = start.mount(render_context);
130+
let ui_handle = f(ui_handle, render_context);
131+
let end = end.mount(render_context);
132+
133+
CursorPlaceholdersSurrounded {
134+
cursor_placeholders: [start, end],
135+
ui_handle,
136+
}
137+
}
138+
139+
pub fn mount_and_map_and_output<R: ?Sized + RenderWithContext, Out, MUH>(
116140
//
117141
self,
118142
render_context: &mut R::RenderContext<'_>,

packages/frender-keyed-elements/src/csr/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<K: Hash + Eq, E: CsrElement> KeyedElementsAlgorithm<K, E> for DefaultAlgori
316316
{
317317
render_context
318318
.map_mut_render_context(|render_context| {
319-
unmounted_ui_handle.mount_and_map(
319+
unmounted_ui_handle.mount_and_map_and_output(
320320
render_context,
321321
|UnmountedUiHandles(unmounted_ui_handles), render_context| {
322322
debug_assert_eq!(unmounted_ui_handles.len(), key_to_state.len());

packages/frender/src/hooks_ext.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use hooks::{ShareValue, ToOwnedShareValue};
22

3-
use crate::fn_traits::{FnMut1, FnMut2};
3+
use crate::fn_traits::FnMut1;
4+
#[cfg(feature = "Memo")]
5+
use crate::fn_traits::FnMut2;
46

57
pub mod callback;
68
pub mod element;
@@ -46,6 +48,7 @@ pub trait ShareValueExt: ShareValue {
4648
self.to_owned_share_value().into_set_form_control_value()
4749
}
4850

51+
#[cfg(feature = "ToElement")]
4952
fn into_element(self) -> element::SignalIntoElement<Self, element::WithToElement>
5053
where
5154
Self: Sized,
@@ -54,6 +57,7 @@ pub trait ShareValueExt: ShareValue {
5457
element::SignalIntoElement(self, element::WithToElement)
5558
}
5659

60+
#[cfg(feature = "ToElement")]
5761
fn to_element(
5862
&self,
5963
) -> element::SignalIntoElement<Self::OwnedShareValue, element::WithToElement>
@@ -83,6 +87,7 @@ pub trait ShareValueExt: ShareValue {
8387
self.to_owned_share_value().into_element_with_fn(f)
8488
}
8589

90+
#[cfg(feature = "Memo")]
8691
fn into_element_with_memo<F, Dep>(
8792
self,
8893
f: F,
@@ -96,6 +101,7 @@ pub trait ShareValueExt: ShareValue {
96101
element::SignalIntoElement(self, crate::Memo(f, dep))
97102
}
98103

104+
#[cfg(feature = "Memo")]
99105
fn to_element_with_memo<F, Dep>(
100106
&self,
101107
f: F,

0 commit comments

Comments
 (0)