Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/stores/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use dioxus_core::{
use dioxus_signals::{
read_impls, write_impls, BorrowError, BorrowMutError, BoxedSignalStorage, CopyValue,
CreateBoxedSignalStorage, Global, InitializeFromFunction, MappedMutSignal, ReadSignal,
Readable, ReadableExt, ReadableRef, Storage, UnsyncStorage, Writable, WritableExt, WritableRef,
WriteSignal,
Readable, ReadableExt, ReadableRef, Storage, SyncStorage, UnsyncStorage, Writable, WritableExt,
WritableRef, WriteSignal,
};
use std::marker::PhantomData;

Expand All @@ -27,6 +27,9 @@ pub type ReadStore<T, S = UnsyncStorage> = Store<T, ReadSignal<T, S>>;
/// A type alias for a boxed writable-only store.
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
/// for each field/member of the data structure as needed.
///
Expand Down Expand Up @@ -404,6 +407,14 @@ pub fn use_store<T: 'static>(init: impl FnOnce() -> T) -> Store<T> {
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
///
/// # Example
Expand Down
Loading