mirror of
https://github.com/Zenithsiz/dynatos.git
synced 2026-02-08 21:09:52 +00:00
Improved signal impls in dynatos.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
// Imports
|
||||
use {
|
||||
crate::ObjectAttachEffect,
|
||||
dynatos_reactive::{Derived, Effect, Signal, SignalWith},
|
||||
dynatos_reactive::{Derived, Effect, Signal, SignalWith, WithDefault},
|
||||
dynatos_router::QuerySignal,
|
||||
dynatos_util::{TryOrReturnExt, WeakRef},
|
||||
};
|
||||
|
||||
@@ -142,23 +143,14 @@ where
|
||||
}
|
||||
|
||||
// TODO: Allow impl for `impl SignalGet<Value: WithDynText>`
|
||||
impl<T> WithDynAttr for Signal<T>
|
||||
where
|
||||
T: WithDynAttr,
|
||||
{
|
||||
fn with_attr<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(Option<&str>) -> O,
|
||||
{
|
||||
self.with(|text| text.with_attr(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F> WithDynAttr for Derived<T, F>
|
||||
where
|
||||
T: WithDynAttr,
|
||||
F: ?Sized,
|
||||
{
|
||||
#[duplicate::duplicate_item(
|
||||
Generics Ty;
|
||||
[T] [Signal<T> where T: WithDynAttr];
|
||||
[T, F] [Derived<T, F> where T: WithDynAttr, F: ?Sized];
|
||||
[T] [QuerySignal<T> where T: WithDynAttr];
|
||||
[S, T] [WithDefault<S, T> where S:SignalWith<Value = Option<T>>, T: WithDynAttr];
|
||||
)]
|
||||
impl<Generics> WithDynAttr for Ty {
|
||||
fn with_attr<F2, O>(&self, f: F2) -> O
|
||||
where
|
||||
F2: FnOnce(Option<&str>) -> O,
|
||||
@@ -196,19 +188,13 @@ impl DynAttrPred for bool {
|
||||
}
|
||||
|
||||
// TODO: Allow impl for `impl SignalGet<Value: WithDynText>`
|
||||
impl<T> DynAttrPred for Signal<T>
|
||||
where
|
||||
T: DynAttrPred,
|
||||
{
|
||||
fn eval(&self) -> bool {
|
||||
self.with(T::eval)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, F: ?Sized> DynAttrPred for Derived<T, F>
|
||||
where
|
||||
T: DynAttrPred,
|
||||
{
|
||||
#[duplicate::duplicate_item(
|
||||
Generics Ty;
|
||||
[T] [Signal<T> where T: DynAttrPred];
|
||||
[T, F] [Derived<T, F> where T: DynAttrPred, F: ?Sized];
|
||||
[S, T] [WithDefault<S, T> where S:SignalWith<Value = Option<T>>, T: DynAttrPred];
|
||||
)]
|
||||
impl<Generics> DynAttrPred for Ty {
|
||||
fn eval(&self) -> bool {
|
||||
self.with(T::eval)
|
||||
}
|
||||
|
||||
@@ -113,22 +113,14 @@ where
|
||||
}
|
||||
|
||||
// TODO: Allow impl for `impl SignalGet<Value: WithDynText>`
|
||||
impl<T> WithDynText for Signal<T>
|
||||
where
|
||||
T: WithDynText,
|
||||
{
|
||||
fn with_text<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(Option<&str>) -> O,
|
||||
{
|
||||
self.with(|text| text.with_text(f))
|
||||
}
|
||||
}
|
||||
impl<T, F> WithDynText for Derived<T, F>
|
||||
where
|
||||
T: WithDynText,
|
||||
F: ?Sized,
|
||||
{
|
||||
#[duplicate::duplicate_item(
|
||||
Generics Ty;
|
||||
[T] [Signal<T> where T: WithDynText];
|
||||
[T, F] [Derived<T, F> where T: WithDynText, F: ?Sized];
|
||||
[T] [QuerySignal<T> where T: WithDynText];
|
||||
[S, T] [WithDefault<S, T> where S:SignalWith<Value = Option<T>>, T: WithDynText];
|
||||
)]
|
||||
impl<Generics> WithDynText for Ty {
|
||||
fn with_text<F2, O>(&self, f: F2) -> O
|
||||
where
|
||||
F2: FnOnce(Option<&str>) -> O,
|
||||
@@ -136,26 +128,3 @@ where
|
||||
self.with(|text| text.with_text(f))
|
||||
}
|
||||
}
|
||||
impl<T> WithDynText for QuerySignal<T>
|
||||
where
|
||||
T: WithDynText,
|
||||
{
|
||||
fn with_text<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(Option<&str>) -> O,
|
||||
{
|
||||
self.with(|text| text.with_text(f))
|
||||
}
|
||||
}
|
||||
impl<S, T> WithDynText for WithDefault<S, T>
|
||||
where
|
||||
S: SignalWith<Value = Option<T>>,
|
||||
T: WithDynText,
|
||||
{
|
||||
fn with_text<F, O>(&self, f: F) -> O
|
||||
where
|
||||
F: FnOnce(Option<&str>) -> O,
|
||||
{
|
||||
self.with(|text| text.with_text(f))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,36 +140,14 @@ impl ToDynProp for Ty {
|
||||
}
|
||||
|
||||
// TODO: Allow impl for `impl SignalGet<Value: WithDynText>`
|
||||
impl<T> ToDynProp for Signal<T>
|
||||
where
|
||||
T: ToDynProp,
|
||||
{
|
||||
fn to_prop(&self) -> Option<JsValue> {
|
||||
self.with(|prop| prop.to_prop())
|
||||
}
|
||||
}
|
||||
impl<T, F> ToDynProp for Derived<T, F>
|
||||
where
|
||||
T: ToDynProp,
|
||||
F: ?Sized,
|
||||
{
|
||||
fn to_prop(&self) -> Option<JsValue> {
|
||||
self.with(|prop| prop.to_prop())
|
||||
}
|
||||
}
|
||||
impl<T> ToDynProp for QuerySignal<T>
|
||||
where
|
||||
T: ToDynProp,
|
||||
{
|
||||
fn to_prop(&self) -> Option<JsValue> {
|
||||
self.with(|prop| prop.to_prop())
|
||||
}
|
||||
}
|
||||
impl<S, T> ToDynProp for WithDefault<S, T>
|
||||
where
|
||||
S: SignalWith<Value = Option<T>>,
|
||||
T: ToDynProp,
|
||||
{
|
||||
#[duplicate::duplicate_item(
|
||||
Generics Ty;
|
||||
[T] [Signal<T> where T: ToDynProp];
|
||||
[T, F] [Derived<T, F> where T: ToDynProp, F: ?Sized];
|
||||
[T] [QuerySignal<T> where T: ToDynProp];
|
||||
[S, T] [WithDefault<S, T> where S:SignalWith<Value = Option<T>>, T: ToDynProp];
|
||||
)]
|
||||
impl<Generics> ToDynProp for Ty {
|
||||
fn to_prop(&self) -> Option<JsValue> {
|
||||
self.with(|prop| prop.to_prop())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user