improved documentation and refactored naming to be more self-explanatory

This commit is contained in:
Pascal committed 2023-12-07 16:36:20 +01:00
1 parent e4d60c8dfc
commit adfbb6c380
91 files changed
+1663 -1553

No files matched your search

+6 -5
View File
@@ -87,11 +87,12 @@ impl Effect {
///
/// The signal will be owned by the current component and will be dropped when the component is dropped.
pub fn new(callback: impl FnMut() + 'static) -> Self {
let myself = Self {
source: current_scope_id().expect("in a virtual dom"),
callback: CopyValue::new(Box::new(callback)),
effect_stack: get_effect_stack(),
};
let myself =
Self {
source: current_scope_id().expect("in a virtual dom"),
callback: CopyValue::new(Box::new(callback)),
effect_stack: get_effect_stack(),
};
myself.try_run();
+4 -3
View File
@@ -72,9 +72,10 @@ where
///
/// Selectors can be used to efficiently compute derived data from signals.
pub fn selector<R: PartialEq>(mut f: impl FnMut() -> R + 'static) -> ReadOnlySignal<R> {
let state = Signal::<R> {
inner: CopyValue::invalid(),
};
let state =
Signal::<R> {
inner: CopyValue::invalid(),
};
let effect = Effect {
source: current_scope_id().expect("in a virtual dom"),
callback: CopyValue::invalid(),
+23 -20
View File
@@ -6,13 +6,14 @@ use dioxus_signals::*;
#[test]
fn create_signals_global() {
let mut dom = VirtualDom::new(|cx| {
render! {
for _ in 0..10 {
Child {}
let mut dom =
VirtualDom::new(|cx| {
render! {
for _ in 0..10 {
Child {}
}
}
}
});
});
fn Child(cx: Scope) -> Element {
let signal = create_without_cx();
@@ -31,13 +32,14 @@ fn create_signals_global() {
#[test]
fn deref_signal() {
let mut dom = VirtualDom::new(|cx| {
render! {
for _ in 0..10 {
Child {}
let mut dom =
VirtualDom::new(|cx| {
render! {
for _ in 0..10 {
Child {}
}
}
}
});
});
fn Child(cx: Scope) -> Element {
let signal = Signal::new("hello world".to_string());
@@ -55,16 +57,17 @@ fn deref_signal() {
#[test]
fn drop_signals() {
let mut dom = VirtualDom::new(|cx| {
let generation = cx.generation();
let mut dom =
VirtualDom::new(|cx| {
let generation = cx.generation();
let count = if generation % 2 == 0 { 10 } else { 0 };
render! {
for _ in 0..count {
Child {}
let count = if generation % 2 == 0 { 10 } else { 0 };
render! {
for _ in 0..count {
Child {}
}
}
}
});
});
fn Child(cx: Scope) -> Element {
let signal = create_without_cx();
+9 -8
View File
@@ -100,14 +100,15 @@ fn memos_prevents_component_rerun() {
let signal = cx.props.signal;
counter.borrow_mut().component += 1;
let memo = cx.use_hook(move || {
to_owned![counter];
selector(move || {
counter.borrow_mut().effect += 1;
println!("Signal: {:?}", signal);
signal.value()
})
});
let memo =
cx.use_hook(move || {
to_owned![counter];
selector(move || {
counter.borrow_mut().effect += 1;
println!("Signal: {:?}", signal);
signal.value()
})
});
match cx.generation() {
0 => {
assert_eq!(memo.value(), 0);