feat: update leptos to v0.7-beta

This commit is contained in:
luoxiao 2024-07-28 00:48:30 +08:00
parent 767fb97e3a
commit 35a6ff309f
4 changed files with 37 additions and 24 deletions

View file

@ -16,5 +16,5 @@ thaw_components = { version = "0.1.1", path = "./thaw_components" }
thaw_macro = { version = "0.1.0", path = "./thaw_macro" } thaw_macro = { version = "0.1.0", path = "./thaw_macro" }
thaw_utils = { version = "0.0.3", path = "./thaw_utils" } thaw_utils = { version = "0.0.3", path = "./thaw_utils" }
leptos = { git = "https://github.com/leptos-rs/leptos", rev = "f8c7a237" } leptos = "0.7.0-beta"
leptos_meta = { git = "https://github.com/leptos-rs/leptos", rev = "f8c7a237" } leptos_meta = "0.7.0-beta"

View file

@ -9,7 +9,7 @@ edition = "2021"
[dependencies] [dependencies]
leptos = { workspace = true } leptos = { workspace = true }
leptos_meta = { 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" } thaw = { path = "../thaw" }
demo_markdown = { path = "../demo_markdown" } demo_markdown = { path = "../demo_markdown" }
icondata = "0.3.0" icondata = "0.3.0"

View file

@ -1,49 +1,59 @@
use leptos::{ use leptos::{
logging::debug_warn, logging::debug_warn,
reactive_graph::{ reactive_graph::{
signal::RwSignal, owner::{Storage, SyncStorage},
signal::{ArcReadSignal, ArcRwSignal, ArcWriteSignal, RwSignal},
traits::{Get, GetUntracked, Update}, traits::{Get, GetUntracked, Update},
}, },
}; };
pub struct ComponentRef<T: 'static>(RwSignal<Option<T>>); pub struct ComponentRef<T, S = SyncStorage>(RwSignal<Option<T>, S>);
impl<T: Send + Sync> Default for ComponentRef<T> { impl<T> Default for ComponentRef<T>
where
T: Send + Sync + 'static,
{
fn default() -> Self { fn default() -> Self {
Self(RwSignal::new(None)) Self(RwSignal::new(None))
} }
} }
impl<T> Clone for ComponentRef<T> { impl<T, S> Clone for ComponentRef<T, S> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
*self Self(self.0.clone())
} }
} }
impl<T: 'static> Copy for ComponentRef<T> {} impl<T, S> Copy for ComponentRef<T, S> {}
// TODO impl<T> ComponentRef<T>
impl<T: Send + Sync> ComponentRef<T> { where
T: Send + Sync + 'static,
{
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()
} }
} }
impl<T> ComponentRef<T> { impl<T, S> ComponentRef<T, S>
pub fn get(&self) -> Option<T> where
where T: Clone + 'static,
T: Clone, S: Storage<ArcRwSignal<Option<T>>> + Storage<ArcReadSignal<Option<T>>>,
{ {
pub fn get(&self) -> Option<T> {
self.0.get() self.0.get()
} }
pub fn get_untracked(&self) -> Option<T> pub fn get_untracked(&self) -> Option<T> {
where
T: Clone,
{
self.0.get_untracked() self.0.get_untracked()
} }
}
impl<T, S> ComponentRef<T, S>
where
T: 'static,
S: Storage<ArcRwSignal<Option<T>>> + Storage<ArcWriteSignal<Option<T>>>,
{
pub fn load(&self, comp: T) { pub fn load(&self, comp: T) {
self.0.update(|current| { self.0.update(|current| {
if current.is_some() { if current.is_some() {

View file

@ -1,6 +1,7 @@
use leptos::reactive_graph::{ use leptos::reactive_graph::{
effect::Effect, effect::Effect,
signal::RwSignal, owner::Storage,
signal::{ArcReadSignal, ArcRwSignal, RwSignal},
traits::{Dispose, With}, traits::{Dispose, With},
untrack, untrack,
}; };
@ -11,10 +12,12 @@ pub trait SignalWatch {
fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()>; fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()>;
} }
impl<T: 'static> SignalWatch for RwSignal<T> { impl<T, S> SignalWatch for RwSignal<T, S>
where
T: 'static,
S: Storage<ArcRwSignal<T>> + Storage<ArcReadSignal<T>>,
{
type Value = T; type Value = T;
/// Listens for RwSignal changes and is not executed immediately
/// ///
/// ## Usage /// ## Usage
/// ///