Expand description
A global Store
The store holds global app app data with static lifetime.
It can be manipulated by dispatching actions (See Action).
Each action is handled by the reducer - A function which matches the action and has a mutable ref to the state in the store.
The reducer must not have any side effects (E.g. saving the state to a file).
Side effects are implemented in middlewares (See Middleware).
Implementations
sourceimpl<S: Debug + Clone + Default + PartialEq + Eq> Store<S>
impl<S: Debug + Clone + Default + PartialEq + Eq> Store<S>
sourcepub fn new(
default_state: S,
reducer: impl Fn(&Action, &mut S) + 'static,
middlewares: Vec<Box<dyn Middleware<S>>>
) -> Self
pub fn new(
default_state: S,
reducer: impl Fn(&Action, &mut S) + 'static,
middlewares: Vec<Box<dyn Middleware<S>>>
) -> Self
Create a new Store.
Arguments
- default_state: The initial state of the store.
- reducer: The root reducer for this store.
- middlewares: A list of Middleware.
sourcepub fn select(
&mut self,
name: &str,
selector: impl Fn(&S) -> S + 'static,
callback: impl Fn(&S) + 'static
)
pub fn select(
&mut self,
name: &str,
selector: impl Fn(&S) -> S + 'static,
callback: impl Fn(&S) + 'static
)
Select a slice of the state where everything else is Default::default().
sourcepub fn select_full(
&mut self,
name: &str,
selector: impl Fn(&S) -> S + 'static,
callback: impl Fn(&S) + 'static
)
pub fn select_full(
&mut self,
name: &str,
selector: impl Fn(&S) -> S + 'static,
callback: impl Fn(&S) + 'static
)
Select a slice of the state with receiving the whole state.
sourcepub fn dispatch(&self, action: String, argument: Option<String>)
pub fn dispatch(&self, action: String, argument: Option<String>)
Dispatch the given arguments as an Action.
NOTE:
This is a placeholder since rustdoc server can not compile latest gtk yet The actual signature looks like this:
pub fn dispatch(&self, action: String, argument: Option<glib::Variant>)
sourcepub fn delegate(&'static self)
pub fn delegate(&'static self)
Delegate GTK actions as gstore::Actions to this store.
NOTE:
This is a placeholder since rustdoc server can not compile latest gtk yet The actual signature looks like this:
pub fn delegate(&'static self) -> glib::Sender<(gdk4::gio::SimpleAction, Option<glib::Variant>)>
Trait Implementations
Auto Trait Implementations
impl<S> !RefUnwindSafe for Store<S>
impl<S> !Send for Store<S>
impl<S> !Sync for Store<S>
impl<S> Unpin for Store<S> where
S: Unpin,
impl<S> !UnwindSafe for Store<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more