Skip to content

Commit

Permalink
feat: support IntoSplitSignal for (Signal<T>, SignalSetter<T>) (c…
Browse files Browse the repository at this point in the history
…loses #3634) (#3643)
  • Loading branch information
gbj authored Feb 25, 2025
1 parent f003e50 commit efcb6f6
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions tachys/src/reactive_graph/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
use reactive_graph::owner::Storage;
use reactive_graph::{
signal::{ReadSignal, RwSignal, WriteSignal},
traits::{Get, Update},
traits::{Get, Set},
wrappers::read::Signal,
};
#[cfg(feature = "reactive_stores")]
Expand Down Expand Up @@ -129,7 +129,7 @@ where
Key: AttributeKey,
T: FromEventTarget + AttributeValue + 'static,
R: Get<Value = T> + Clone + 'static,
W: Update<Value = T>,
W: Set<Value = T>,
{
key: Key,
read_signal: R,
Expand All @@ -141,7 +141,7 @@ where
Key: AttributeKey,
T: FromEventTarget + AttributeValue + 'static,
R: Get<Value = T> + Clone + 'static,
W: Update<Value = T> + Clone,
W: Set<Value = T> + Clone,
{
fn clone(&self) -> Self {
Self {
Expand All @@ -157,7 +157,7 @@ where
Key: AttributeKey,
T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static,
R: Get<Value = T> + Clone + Send + Sync + 'static,
W: Update<Value = T> + Clone + 'static,
W: Set<Value = T> + Clone + 'static,
Element: ChangeEvent + GetValue<T>,
{
/// Attaches the event listener that updates the signal value to the element.
Expand Down Expand Up @@ -198,7 +198,7 @@ where
T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static,
R: Get<Value = T> + Clone + Send + Sync + 'static,
Signal<BoolOrT<T>>: IntoProperty,
W: Update<Value = T> + Clone + Send + 'static,
W: Set<Value = T> + Clone + Send + 'static,
Element: ChangeEvent + GetValue<T>,
{
const MIN_LENGTH: usize = 0;
Expand Down Expand Up @@ -278,7 +278,7 @@ where
T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static,
R: Get<Value = T> + Clone + Send + Sync + 'static,
Signal<BoolOrT<T>>: IntoProperty,
W: Update<Value = T> + Clone + Send + 'static,
W: Set<Value = T> + Clone + Send + 'static,
Element: ChangeEvent + GetValue<T>,
{
next_attr_output_type!(Self, NewAttr);
Expand All @@ -296,7 +296,7 @@ where
Key: AttributeKey,
T: FromEventTarget + AttributeValue + 'static,
R: Get<Value = T> + Clone + 'static,
W: Update<Value = T> + Clone,
W: Set<Value = T> + Clone,
{
#[inline(always)]
fn to_template(
Expand All @@ -318,7 +318,7 @@ pub trait IntoSplitSignal {
/// The read part of the signal
type Read: Get<Value = Self::Value>;
/// The write part of the signal
type Write: Update<Value = Self::Value>;
type Write: Set<Value = Self::Value>;
/// Splits a combined signal into its read and write parts.
fn into_split_signal(self) -> (Self::Read, Self::Write);
}
Expand All @@ -340,7 +340,7 @@ where
impl<T, R, W> IntoSplitSignal for (R, W)
where
R: Get<Value = T>,
W: Update<Value = T>,
W: Set<Value = T>,
{
type Value = T;
type Read = R;
Expand All @@ -354,7 +354,7 @@ where
#[cfg(feature = "reactive_stores")]
impl<Inner, Prev, T> IntoSplitSignal for Subfield<Inner, Prev, T>
where
Self: Get<Value = T> + Update<Value = T> + Clone,
Self: Get<Value = T> + Set<Value = T> + Clone,
{
type Value = T;
type Read = Self;
Expand All @@ -368,7 +368,7 @@ where
#[cfg(feature = "reactive_stores")]
impl<T, S> IntoSplitSignal for Field<T, S>
where
Self: Get<Value = T> + Update<Value = T> + Clone,
Self: Get<Value = T> + Set<Value = T> + Clone,
S: Storage<ArcField<T>>,
{
type Value = T;
Expand All @@ -383,7 +383,7 @@ where
#[cfg(feature = "reactive_stores")]
impl<Inner, Prev, K, T> IntoSplitSignal for KeyedSubfield<Inner, Prev, K, T>
where
Self: Get<Value = T> + Update<Value = T> + Clone,
Self: Get<Value = T> + Set<Value = T> + Clone,
for<'a> &'a T: IntoIterator,
{
type Value = T;
Expand Down Expand Up @@ -425,7 +425,7 @@ pub trait ChangeEvent {
) -> RemoveEventHandler<Self>
where
T: FromEventTarget + AttributeValue + 'static,
W: Update<Value = T> + 'static,
W: Set<Value = T> + 'static,
Self: Sized;
}

Expand All @@ -437,21 +437,20 @@ impl ChangeEvent for web_sys::Element {
) -> RemoveEventHandler<Self>
where
T: FromEventTarget + AttributeValue + 'static,
W: Update<Value = T> + 'static,
W: Set<Value = T> + 'static,
{
if key == "group" {
let handler = move |evt| {
let checked = event_target_checked(&evt);
if checked {
write_signal
.try_update(|v| *v = T::from_event_target(&evt));
write_signal.try_set(T::from_event_target(&evt));
}
};

on::<_, _>(change, handler).attach(self)
} else {
let handler = move |evt| {
write_signal.try_update(|v| *v = T::from_event_target(&evt));
write_signal.try_set(T::from_event_target(&evt));
};

if key == "checked" || self.tag_name() == "SELECT" {
Expand Down

0 comments on commit efcb6f6

Please sign in to comment.