[−][src]Struct redux_rs::Store
A container holding a state and providing the possibility to dispatch actions.
A store is defined by the state is holds and the actions it can dispatch.
Methods
impl<State, Action> Store<State, Action>
[src]
pub fn new(reducer: Reducer<State, Action>, initial_state: State) -> Self
[src]
Creates a new store.
Example
type State = i8; enum Action { Increment, Decrement } fn reducer(state: &State, action: &Action) -> State { match action { Action::Increment => state + 1, Action::Decrement => state - 1 } } let mut store = Store::new(reducer, 0);
pub fn state(&self) -> &State
[src]
pub fn dispatch(&mut self, action: Action)
[src]
Dispatches an action which is handles by the reducer, after the store got passed through the middleware. This can modify the state within the store.
Example
enum Action { DoSomething, DoSomethingElse } // ... store.dispatch(Action::DoSomething); println!("Current state: {}", store.state());
pub fn subscribe(&mut self, callback: Subscription<State>)
[src]
Subscribes a callback to any change of the state.
Subscriptions will be called, whenever an action is dispatched.
See Subscription
.
Example
use redux_rs::{Store, Subscription}; let mut store = Store::new(reducer, initial_state); let listener: Subscription<State> = |state: &State| { println!("Something changed! New value: {}", state); }; store.subscribe(listener);
pub fn add_middleware(&mut self, middleware: Middleware<State, Action>)
[src]
Adds a custom middleware to the store.
Middleware provides the possibility to intercept actions dispatched before they reach the reducer.
See Middleware
.
pub fn replace_reducer(&mut self, reducer: Reducer<State, Action>)
[src]
Replaces the currently used reducer.
Example
store.dispatch(Action::SomeAction); store.replace_reducer(|state: &State, action: &Action| { State::something_else() }); store.dispatch(Action::SomeAction);
Auto Trait Implementations
impl<State, Action> Send for Store<State, Action> where
State: Send,
State: Send,
impl<State, Action> Sync for Store<State, Action> where
State: Sync,
State: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,