Add SyncStore and use_store_sync (#5014)
This commit is contained in:
1 parent
84efc00757
commit
f7e102a0b4
1 file changed
+13
-2
@@ -8,8 +8,8 @@ use dioxus_core::{
|
|||||||
use dioxus_signals::{
|
use dioxus_signals::{
|
||||||
read_impls, write_impls, BorrowError, BorrowMutError, BoxedSignalStorage, CopyValue,
|
read_impls, write_impls, BorrowError, BorrowMutError, BoxedSignalStorage, CopyValue,
|
||||||
CreateBoxedSignalStorage, Global, InitializeFromFunction, MappedMutSignal, ReadSignal,
|
CreateBoxedSignalStorage, Global, InitializeFromFunction, MappedMutSignal, ReadSignal,
|
||||||
Readable, ReadableExt, ReadableRef, Storage, UnsyncStorage, Writable, WritableExt, WritableRef,
|
Readable, ReadableExt, ReadableRef, Storage, SyncStorage, UnsyncStorage, Writable, WritableExt,
|
||||||
WriteSignal,
|
WritableRef, WriteSignal,
|
||||||
};
|
};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@@ -27,6 +27,9 @@ pub type ReadStore<T, S = UnsyncStorage> = Store<T, ReadSignal<T, S>>;
|
|||||||
/// A type alias for a boxed writable-only store.
|
/// A type alias for a boxed writable-only store.
|
||||||
pub type WriteStore<T, S = UnsyncStorage> = Store<T, WriteSignal<T, S>>;
|
pub type WriteStore<T, S = UnsyncStorage> = Store<T, WriteSignal<T, S>>;
|
||||||
|
|
||||||
|
/// A type alias for a store backed by SyncStorage.
|
||||||
|
pub type SyncStore<T> = Store<T, CopyValue<T, SyncStorage>>;
|
||||||
|
|
||||||
/// Stores are a reactive type built for nested data structures. Each store will lazily create signals
|
/// Stores are a reactive type built for nested data structures. Each store will lazily create signals
|
||||||
/// for each field/member of the data structure as needed.
|
/// for each field/member of the data structure as needed.
|
||||||
///
|
///
|
||||||
@@ -404,6 +407,14 @@ pub fn use_store<T: 'static>(init: impl FnOnce() -> T) -> Store<T> {
|
|||||||
use_hook(move || Store::new(init()))
|
use_hook(move || Store::new(init()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new [`SyncStore`]. Stores are a reactive type built for nested data structures.
|
||||||
|
/// `SyncStore` is a Store backed by `SyncStorage`.
|
||||||
|
///
|
||||||
|
/// Like [`use_store`], but produces `SyncStore<T>` instead of `Store<T>`
|
||||||
|
pub fn use_store_sync<T: Send + Sync + 'static>(init: impl FnOnce() -> T) -> SyncStore<T> {
|
||||||
|
use_hook(|| Store::new_maybe_sync(init()))
|
||||||
|
}
|
||||||
|
|
||||||
/// A type alias for global stores
|
/// A type alias for global stores
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
|||||||
Reference in new issue
Block a user