Skip to content

Commit

Permalink
fix signal() equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Dec 17, 2024
1 parent ad70d56 commit 1d47740
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion reactive_graph/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ pub fn arc_signal<T>(value: T) -> (ArcReadSignal<T>, ArcWriteSignal<T>) {
pub fn signal<T: Send + Sync + 'static>(
value: T,
) -> (ReadSignal<T>, WriteSignal<T>) {
RwSignal::new(value).split()
let (r, w) = arc_signal(value);
(r.into(), w.into())
}

/// Creates an arena-allocated signal.
Expand Down
15 changes: 13 additions & 2 deletions reactive_graph/tests/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use reactive_graph::{
owner::Owner,
signal::{arc_signal, signal, ArcRwSignal, RwSignal},
traits::{
Get, GetUntracked, IntoInner, Read, Set, Update, UpdateUntracked, With,
WithUntracked, Write,
Dispose, Get, GetUntracked, IntoInner, Read, Set, Update,
UpdateUntracked, With, WithUntracked, Write,
},
};

Expand Down Expand Up @@ -129,3 +129,14 @@ fn into_inner_arc_signal() {
std::mem::drop(b);
assert_eq!(a.into_inner(), Some(2));
}

#[test]
fn into_inner_non_arc_signal() {
let owner = Owner::new();
owner.set();

let (a, b) = signal(2);
assert_eq!(a.get(), 2);
b.dispose();
assert_eq!(a.into_inner(), Some(2));
}

0 comments on commit 1d47740

Please sign in to comment.