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:
1 parent
668d5415c8
commit
b47a6cf83e
13 files changed
+281
-289
No files matched your search
+2
-2
@@ -10,7 +10,7 @@ use dioxus::prelude::*;
|
||||
const STYLE: &str = asset!("./examples/assets/counter.css");
|
||||
|
||||
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
|
||||
static DOUBLED_COUNT: GlobalMemo<i32> = Signal::global_memo(|| COUNT() * 2);
|
||||
static DOUBLED_COUNT: GlobalMemo<i32> = Memo::global(|| COUNT() * 2);
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
@@ -52,7 +52,7 @@ fn Display() -> Element {
|
||||
fn Reset() -> Element {
|
||||
// Not all write methods are available on global signals since `write` requires a mutable reference. In these cases,
|
||||
// We can simply pull out the actual signal using the signal() method.
|
||||
let mut as_signal = use_hook(|| COUNT.signal());
|
||||
let mut as_signal = use_hook(|| COUNT.resolve());
|
||||
|
||||
rsx! {
|
||||
button { onclick: move |_| as_signal.set(0), "Reset" }
|
||||
|
||||
Reference in new issue
Block a user