only implement T -> Readonlysignal
This commit is contained in:
1 parent
1c67585ba2
commit
1f88103dca
4 files changed
+26
-15
No files matched your search
+2
-4
@@ -59,15 +59,13 @@ fn app() -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// You can pass a value directly to any prop that accepts a signal
|
// You can pass a value directly to any prop that accepts a signal
|
||||||
Child { count: 0 }
|
Child { count: doubled_count() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn Child(mut count: Signal<i32>) -> Element {
|
fn Child(mut count: ReadOnlySignal<i32>) -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
h1 { "{count}" }
|
h1 { "{count}" }
|
||||||
button { onclick: move |_| count += 1, "Up high!" }
|
|
||||||
button { onclick: move |_| count -= 1, "Down low!" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -584,7 +584,7 @@ mod struct_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn memoize_impl(&self) -> Result<TokenStream, Error> {
|
fn memoize_impl(&self) -> Result<TokenStream, Error> {
|
||||||
// First check if there are any Signal fields, if there are not, we can just use the partialEq impl
|
// First check if there are any ReadOnlySignal fields, if there are not, we can just use the partialEq impl
|
||||||
let has_signal_fields = self.has_signal_fields();
|
let has_signal_fields = self.has_signal_fields();
|
||||||
|
|
||||||
if has_signal_fields {
|
if has_signal_fields {
|
||||||
@@ -647,7 +647,7 @@ mod struct_info {
|
|||||||
(&old_value).compare(&&new_value)
|
(&old_value).compare(&&new_value)
|
||||||
};
|
};
|
||||||
if !field_eq {
|
if !field_eq {
|
||||||
(#signal_fields).set(new.#signal_fields.take());
|
(#signal_fields).__set(new.#signal_fields.__take());
|
||||||
}
|
}
|
||||||
// Move the old value back
|
// Move the old value back
|
||||||
self.#signal_fields = #signal_fields;
|
self.#signal_fields = #signal_fields;
|
||||||
@@ -1564,9 +1564,9 @@ fn looks_like_signal_type(ty: &Type) -> bool {
|
|||||||
segments: Punctuated::from_iter(path_segments_without_generics),
|
segments: Punctuated::from_iter(path_segments_without_generics),
|
||||||
};
|
};
|
||||||
|
|
||||||
path_without_generics == parse_quote!(dioxus_core::prelude::Signal)
|
path_without_generics == parse_quote!(dioxus_core::prelude::ReadOnlySignal)
|
||||||
|| path_without_generics == parse_quote!(prelude::Signal)
|
|| path_without_generics == parse_quote!(prelude::ReadOnlySignal)
|
||||||
|| path_without_generics == parse_quote!(Signal)
|
|| path_without_generics == parse_quote!(ReadOnlySignal)
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
use crate::Signal;
|
use crate::{ReadOnlySignal, Signal};
|
||||||
use dioxus_core::prelude::*;
|
use dioxus_core::prelude::*;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct SignalFromMarker<M>(std::marker::PhantomData<M>);
|
pub struct SignalFromMarker<M>(std::marker::PhantomData<M>);
|
||||||
|
|
||||||
impl<T, O, M> SuperFrom<T, SignalFromMarker<M>> for Signal<O>
|
impl<T, O, M> SuperFrom<T, SignalFromMarker<M>> for ReadOnlySignal<O>
|
||||||
where
|
where
|
||||||
O: SuperFrom<T, M>,
|
O: SuperFrom<T, M>,
|
||||||
{
|
{
|
||||||
fn super_from(input: T) -> Self {
|
fn super_from(input: T) -> Self {
|
||||||
Signal::new(O::super_from(input))
|
ReadOnlySignal::new(Signal::new(O::super_from(input)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn into_signal_compiles() {
|
fn into_signal_compiles() {
|
||||||
fn takes_signal_string<M>(_: impl SuperInto<Signal<String>, M>) {}
|
fn takes_signal_string<M>(_: impl SuperInto<ReadOnlySignal<String>, M>) {}
|
||||||
|
|
||||||
fn takes_option_signal_string<M>(_: impl SuperInto<Signal<Option<String>>, M>) {}
|
fn takes_option_signal_string<M>(_: impl SuperInto<ReadOnlySignal<Option<String>>, M>) {}
|
||||||
|
|
||||||
fn don_t_run() {
|
fn don_t_run() {
|
||||||
takes_signal_string("hello world");
|
takes_signal_string("hello world");
|
||||||
takes_signal_string(Signal::new(String::from("hello world")));
|
takes_signal_string(ReadOnlySignal::new(String::from("hello world")));
|
||||||
takes_option_signal_string("hello world");
|
takes_option_signal_string("hello world");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,19 @@ impl<T: 'static, S: Storage<SignalData<T>>> ReadOnlySignal<T, S> {
|
|||||||
pub fn id(&self) -> generational_box::GenerationalBoxId {
|
pub fn id(&self) -> generational_box::GenerationalBoxId {
|
||||||
self.inner.id()
|
self.inner.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// This should only be used by the `rsx!` macro.
|
||||||
|
pub fn __set(&mut self, value: T) {
|
||||||
|
use crate::write::Writable;
|
||||||
|
self.inner.set(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// This should only be used by the `rsx!` macro.
|
||||||
|
pub fn __take(&self) -> T {
|
||||||
|
self.inner.take()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, S: Storage<SignalData<T>>> Readable<T> for ReadOnlySignal<T, S> {
|
impl<T, S: Storage<SignalData<T>>> Readable<T> for ReadOnlySignal<T, S> {
|
||||||
|
|||||||
Reference in new issue
Block a user