From 35a6ff309f1fd9fd7f803c2cf33664cc6bbea7fe Mon Sep 17 00:00:00 2001 From: luoxiao Date: Sun, 28 Jul 2024 00:48:30 +0800 Subject: [PATCH] feat: update leptos to v0.7-beta --- Cargo.toml | 4 +-- demo/Cargo.toml | 2 +- thaw_utils/src/signals/component_ref.rs | 44 +++++++++++++++---------- thaw_utils/src/signals/signal_watch.rs | 11 ++++--- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91718d8..83f0bf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ thaw_components = { version = "0.1.1", path = "./thaw_components" } thaw_macro = { version = "0.1.0", path = "./thaw_macro" } thaw_utils = { version = "0.0.3", path = "./thaw_utils" } -leptos = { git = "https://github.com/leptos-rs/leptos", rev = "f8c7a237" } -leptos_meta = { git = "https://github.com/leptos-rs/leptos", rev = "f8c7a237" } \ No newline at end of file +leptos = "0.7.0-beta" +leptos_meta = "0.7.0-beta" \ No newline at end of file diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 5afbae3..815fce0 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [dependencies] leptos = { workspace = true } leptos_meta = { workspace = true } -leptos_router = { git = "https://github.com/leptos-rs/leptos", rev = "f8c7a237" } +leptos_router = "0.7.0-beta" thaw = { path = "../thaw" } demo_markdown = { path = "../demo_markdown" } icondata = "0.3.0" diff --git a/thaw_utils/src/signals/component_ref.rs b/thaw_utils/src/signals/component_ref.rs index c94a461..45e2077 100644 --- a/thaw_utils/src/signals/component_ref.rs +++ b/thaw_utils/src/signals/component_ref.rs @@ -1,49 +1,59 @@ use leptos::{ logging::debug_warn, reactive_graph::{ - signal::RwSignal, + owner::{Storage, SyncStorage}, + signal::{ArcReadSignal, ArcRwSignal, ArcWriteSignal, RwSignal}, traits::{Get, GetUntracked, Update}, }, }; -pub struct ComponentRef(RwSignal>); +pub struct ComponentRef(RwSignal, S>); -impl Default for ComponentRef { +impl Default for ComponentRef +where + T: Send + Sync + 'static, +{ fn default() -> Self { Self(RwSignal::new(None)) } } -impl Clone for ComponentRef { +impl Clone for ComponentRef { fn clone(&self) -> Self { - *self + Self(self.0.clone()) } } -impl Copy for ComponentRef {} +impl Copy for ComponentRef {} -// TODO -impl ComponentRef { +impl ComponentRef +where + T: Send + Sync + 'static, +{ pub fn new() -> Self { Self::default() } } -impl ComponentRef { - pub fn get(&self) -> Option - where - T: Clone, - { +impl ComponentRef +where + T: Clone + 'static, + S: Storage>> + Storage>>, +{ + pub fn get(&self) -> Option { self.0.get() } - pub fn get_untracked(&self) -> Option - where - T: Clone, - { + pub fn get_untracked(&self) -> Option { self.0.get_untracked() } +} +impl ComponentRef +where + T: 'static, + S: Storage>> + Storage>>, +{ pub fn load(&self, comp: T) { self.0.update(|current| { if current.is_some() { diff --git a/thaw_utils/src/signals/signal_watch.rs b/thaw_utils/src/signals/signal_watch.rs index c660f59..8e04be0 100644 --- a/thaw_utils/src/signals/signal_watch.rs +++ b/thaw_utils/src/signals/signal_watch.rs @@ -1,6 +1,7 @@ use leptos::reactive_graph::{ effect::Effect, - signal::RwSignal, + owner::Storage, + signal::{ArcReadSignal, ArcRwSignal, RwSignal}, traits::{Dispose, With}, untrack, }; @@ -11,10 +12,12 @@ pub trait SignalWatch { fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box; } -impl SignalWatch for RwSignal { +impl SignalWatch for RwSignal +where + T: 'static, + S: Storage> + Storage>, +{ type Value = T; - - /// Listens for RwSignal changes and is not executed immediately /// /// ## Usage ///