Updated bounds depending on WithDefault's SignalWith impl.

This commit is contained in:
Filipe Rodrigues 2025-05-16 17:43:04 +01:00
parent 42b96c4c9d
commit 25a9ab7b7f
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
3 changed files with 11 additions and 42 deletions

View File

@ -3,6 +3,7 @@
// Imports
use {
crate::ObjectAttachEffect,
core::ops::Deref,
dynatos_html::WeakRef,
dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault},
dynatos_router::QuerySignal,
@ -156,7 +157,8 @@ where
[T] [Signal<T> where T: WithDynAttr + 'static];
[T, F] [Derived<T, F> where T: WithDynAttr + 'static, F: ?Sized + 'static];
[T, F] [Memo<T, F> where T: WithDynAttr + 'static, F: ?Sized + 'static];
[S, T] [WithDefault<S, T> where S: for<'a> SignalWith<Value<'a> = Option<&'a T>>, T: WithDynAttr + 'static];
[S, T] [WithDefault<S, T> where Self: for<'a> SignalWith<Value<'a>: Sized + Deref<Target: WithDynAttr>>];
[T] [QuerySignal<T> where T: WithDynAttr + 'static];
)]
impl<Generics> WithDynAttr for Ty {
fn with_attr<F2, O>(&self, f: F2) -> O
@ -166,20 +168,6 @@ impl<Generics> WithDynAttr for Ty {
self.with(|text| text.with_attr(f))
}
}
impl<T> WithDynAttr for QuerySignal<T>
where
T: WithDynAttr + 'static,
{
fn with_attr<F2, O>(&self, f: F2) -> O
where
F2: FnOnce(Option<&str>) -> O,
{
self.with(|text| match text {
Some(text) => text.with_attr(f),
None => None::<T>.with_attr(f),
})
}
}
/// Trait for values accepted by [`ElementDynAttr::set_dyn_attr_if`].
///
@ -216,10 +204,10 @@ impl DynAttrPred for bool {
[T] [Signal<T> where T: DynAttrPred + 'static];
[T, F] [Derived<T, F> where T: DynAttrPred + 'static, F: ?Sized + 'static];
[T, F] [Memo<T, F> where T: DynAttrPred + 'static, F: ?Sized + 'static];
[S, T] [WithDefault<S, T> where S: for<'a> SignalWith<Value<'a> = Option<&'a T>>, T: DynAttrPred + 'static];
[S, T] [WithDefault<S, T> where Self: for<'a> SignalWith<Value<'a>: Sized + Deref<Target: DynAttrPred>>];
)]
impl<Generics> DynAttrPred for Ty {
fn eval(&self) -> bool {
self.with(T::eval)
self.with(|value| value.eval())
}
}

View File

@ -3,6 +3,7 @@
// Imports
use {
crate::ObjectAttachEffect,
core::ops::Deref,
dynatos_html::WeakRef,
dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault},
dynatos_router::QuerySignal,
@ -124,7 +125,8 @@ where
[T] [Signal<T> where T: WithDynText + 'static];
[T, F] [Derived<T, F> where T: WithDynText + 'static, F: ?Sized + 'static];
[T, F] [Memo<T, F> where T: WithDynText + 'static, F: ?Sized + 'static];
[S, T] [WithDefault<S, T> where S: for<'a> SignalWith<Value<'a> = Option<&'a T>>, T: WithDynText + 'static];
[S, T] [WithDefault<S, T> where Self: for<'a> SignalWith<Value<'a>: Sized + Deref<Target: WithDynText>>];
[T] [QuerySignal<T> where T: WithDynText + 'static];
)]
impl<Generics> WithDynText for Ty {
fn with_text<F2, O>(&self, f: F2) -> O
@ -134,17 +136,3 @@ impl<Generics> WithDynText for Ty {
self.with(|text| text.with_text(f))
}
}
impl<T> WithDynText for QuerySignal<T>
where
T: WithDynText + 'static,
{
fn with_text<F2, O>(&self, f: F2) -> O
where
F2: FnOnce(Option<&str>) -> O,
{
self.with(|text| match text {
Some(text) => text.with_text(f),
None => None::<T>.with_text(f),
})
}
}

View File

@ -3,6 +3,7 @@
// Imports
use {
crate::ObjectAttachEffect,
core::ops::Deref,
dynatos_html::{ObjectRemoveProp, ObjectSetProp, WeakRef},
dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault},
dynatos_router::QuerySignal,
@ -151,19 +152,11 @@ impl ToDynProp for Ty {
[T] [Signal<T> where T: ToDynProp + 'static];
[T, F] [Derived<T, F> where T: ToDynProp + 'static, F: ?Sized + 'static];
[T, F] [Memo<T, F> where T: ToDynProp + 'static, F: ?Sized + 'static];
[S, T] [WithDefault<S, T> where S: for<'a> SignalWith<Value<'a> = Option<&'a T>>, T: ToDynProp + 'static];
[S, T] [WithDefault<S, T> where Self: for<'a> SignalWith<Value<'a>: Sized + Deref<Target: ToDynProp>>];
[T] [QuerySignal<T> where T: ToDynProp + 'static];
)]
impl<Generics> ToDynProp for Ty {
fn to_prop(&self) -> Option<JsValue> {
self.with(|prop| prop.to_prop())
}
}
impl<T> ToDynProp for QuerySignal<T>
where
T: ToDynProp + 'static,
{
fn to_prop(&self) -> Option<JsValue> {
self.with(|prop| prop.as_ref().and_then(T::to_prop))
}
}