Move to a generic GlobalLazy<T> (#2851)

* Expose a generic lazy type

* Switch to generic lazy globals

* simplify global lazy context a bit

* rename LazyGlobal to Global

* use Memo::global in more examples

* Fix soundness issue with deref_impl. It relies on the size of self, so it cannot be safe

* add a comment about safety

* Make clippy happy

* fix formatting

* Restore changes to signal impl

* Add helper methods for global signal and global memo to make getting the inner value easier
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-08-16 17:57:41 -05:00
1 parent 668d5415c8
commit b47a6cf83e
13 files changed
+281 -289

No files matched your search

+7 -4
View File
@@ -1,4 +1,4 @@
use crate::{default_impl, fmt_impls, write_impls};
use crate::{default_impl, fmt_impls, write_impls, Global};
use crate::{read::*, write::*, CopyValue, GlobalMemo, GlobalSignal, ReadableRef};
use crate::{Memo, WritableRef};
use dioxus_core::prelude::*;
@@ -87,7 +87,7 @@ impl<T: 'static> Signal<T> {
/// </div>
#[track_caller]
pub const fn global(constructor: fn() -> T) -> GlobalSignal<T> {
GlobalSignal::new(constructor)
Global::new(constructor)
}
}
@@ -118,7 +118,10 @@ impl<T: PartialEq + 'static> Signal<T> {
///
/// </div>
#[track_caller]
pub const fn global_memo(constructor: fn() -> T) -> GlobalMemo<T> {
pub const fn global_memo(constructor: fn() -> T) -> GlobalMemo<T>
where
T: PartialEq,
{
GlobalMemo::new(constructor)
}
@@ -462,7 +465,7 @@ impl<T: Clone, S: Storage<SignalData<T>> + 'static> Deref for Signal<T, S> {
type Target = dyn Fn() -> T;
fn deref(&self) -> &Self::Target {
Readable::deref_impl(self)
unsafe { Readable::deref_impl(self) }
}
}