1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # Configure Store Module
//!
//! This module provides utilities for easily creating and configuring Redux-style stores.
//! It simplifies the store creation process by handling the boxing of reducers and
//! providing a clean API for store initialization.
//!
//! ## Example
//!
//! ```rust
//! use zed::{configure_store, create_reducer};
//!
//! #[derive(Clone, Debug, PartialEq)]
//! struct AppState {
//! counter: i32,
//! }
//!
//! #[derive(Debug)]
//! enum AppAction {
//! Increment,
//! Decrement,
//! Reset,
//! }
//!
//! // Create a reducer
//! let reducer = create_reducer(|state: &AppState, action: &AppAction| {
//! match action {
//! AppAction::Increment => AppState { counter: state.counter + 1 },
//! AppAction::Decrement => AppState { counter: state.counter - 1 },
//! AppAction::Reset => AppState { counter: 0 },
//! }
//! });
//!
//! // Configure the store easily
//! let mut store = configure_store(AppState { counter: 0 }, reducer);
//!
//! store.dispatch(AppAction::Increment);
//! assert_eq!(store.get_state().counter, 1);
//! ```
use crateReducer;
use crateStore;
/// Configures and creates a new Redux-style store with the given initial state and reducer.
///
/// This is a convenience function that handles the complexity of boxing the reducer
/// and provides a simple way to create stores without dealing with trait objects directly.
///
/// # Arguments
///
/// * `initial_state` - The initial state of the store
/// * `reducer` - A reducer that implements the Reducer trait
///
/// # Type Parameters
///
/// * `State` - The type of the state. Must be Clone + Send + 'static
/// * `Action` - The type of actions. Must be Send + 'static
/// * `R` - The type of the reducer. Must implement Reducer + Send + Sync + 'static
///
/// # Returns
///
/// A new Store instance configured with the provided state and reducer.
///
/// # Example
///
/// ```rust
/// use zed::{configure_store, create_reducer};
///
/// #[derive(Clone)]
/// struct Counter { value: i32 }
///
/// enum Action { Add(i32), Reset }
///
/// let reducer = create_reducer(|state: &Counter, action: &Action| {
/// match action {
/// Action::Add(n) => Counter { value: state.value + n },
/// Action::Reset => Counter { value: 0 },
/// }
/// });
///
/// let mut store = configure_store(Counter { value: 0 }, reducer);
/// store.dispatch(Action::Add(5));
/// assert_eq!(store.get_state().value, 5);
/// ```