Revert "improved documentation and refactored naming to be more self-explanatory"

This reverts commit adfbb6c380.
This commit is contained in:
Pascal committed 2023-12-07 17:11:56 +01:00
1 parent adfbb6c380
commit 906c466e78
91 files changed
+1553 -1663

No files matched your search

+5 -6
View File
@@ -87,12 +87,11 @@ 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();
+3 -4
View File
@@ -72,10 +72,9 @@ 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(),
+20 -23
View File
@@ -6,14 +6,13 @@ 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();
@@ -32,14 +31,13 @@ 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());
@@ -57,17 +55,16 @@ 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();
+8 -9
View File
@@ -100,15 +100,14 @@ 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);