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_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" }
leptos = "0.7.0-beta"
leptos_meta = "0.7.0-beta"

View file

@ -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"

View file

@ -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<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 {
Self(RwSignal::new(None))
}
}
impl<T> Clone for ComponentRef<T> {
impl<T, S> Clone for ComponentRef<T, S> {
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: Send + Sync> ComponentRef<T> {
impl<T> ComponentRef<T>
where
T: Send + Sync + 'static,
{
pub fn new() -> Self {
Self::default()
}
}
impl<T> ComponentRef<T> {
pub fn get(&self) -> Option<T>
where
T: Clone,
{
impl<T, S> ComponentRef<T, S>
where
T: Clone + 'static,
S: Storage<ArcRwSignal<Option<T>>> + Storage<ArcReadSignal<Option<T>>>,
{
pub fn get(&self) -> Option<T> {
self.0.get()
}
pub fn get_untracked(&self) -> Option<T>
where
T: Clone,
{
pub fn get_untracked(&self) -> Option<T> {
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) {
self.0.update(|current| {
if current.is_some() {

View file

@ -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<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;
/// Listens for RwSignal changes and is not executed immediately
///
/// ## Usage
///