All Projects → redux-rs → Redux Rs

redux-rs / Redux Rs

Licence: mit
📦 A Rust implementation of Redux.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Redux Rs

Duix
A State Manager focused on KISS and Pareto's Principle
Stars: ✭ 48 (-69.62%)
Mutual labels:  state-management, state
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-49.37%)
Mutual labels:  state-management, state
Alveron
Elm & Reason inspired state management for React
Stars: ✭ 57 (-63.92%)
Mutual labels:  state-management, state
Contextism
😍 Use React Context better.
Stars: ✭ 141 (-10.76%)
Mutual labels:  state-management, state
Stateshot
💾 Non-aggressive history state management with structure sharing.
Stars: ✭ 128 (-18.99%)
Mutual labels:  state-management, state
Concent
State management that tailored for react, it is simple, predictable, progressive and efficient.
Stars: ✭ 882 (+458.23%)
Mutual labels:  state-management, state
React Composition Api
🎨 Simple React state management. Made with @vue/reactivity and ❤️.
Stars: ✭ 67 (-57.59%)
Mutual labels:  state-management, state
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (+313.92%)
Mutual labels:  state-management, state
Vue State Store
📮 VSS (Vue State Store) - Vue State Management (with Publish & Subscribe pattern)
Stars: ✭ 128 (-18.99%)
Mutual labels:  state-management, state
React Workshop
⚒ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-27.85%)
Mutual labels:  state-management, state
Revived
A redux-inspired predictable state container for python
Stars: ✭ 12 (-92.41%)
Mutual labels:  state-management, state
Pure Store
A tiny immutable store with type safety.
Stars: ✭ 133 (-15.82%)
Mutual labels:  state-management, state
Redux Tree
An alternative way to compose Redux reducers
Stars: ✭ 23 (-85.44%)
Mutual labels:  state-management, state
Use Global Context
A new way to use “useContext” better
Stars: ✭ 34 (-78.48%)
Mutual labels:  state-management, state
Pullstate
Simple state stores using immer and React hooks - re-use parts of your state by pulling it anywhere you like!
Stars: ✭ 683 (+332.28%)
Mutual labels:  state-management, state
Yewdux
Redux-like state containers for Yew apps
Stars: ✭ 58 (-63.29%)
Mutual labels:  state-management, state
Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+2366.46%)
Mutual labels:  state-management, state
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (+258.86%)
Mutual labels:  state-management, state
Reworm
🍫 the simplest way to manage state
Stars: ✭ 1,467 (+828.48%)
Mutual labels:  state-management, state
Swiftdux
Predictable state management for SwiftUI applications.
Stars: ✭ 130 (-17.72%)
Mutual labels:  state-management, state

Build Status Crates.io Documentation Code Coverage

redux-rs

A Rust implementation of Redux.

Redux

Redux, originally implemented in JavaScript, is an functional approach to state management. The core concept is that you have a state and a reducer, a function to create a new state from the old one and an action, a description of what to change. Because the state itself is immutable, this results in a very clean way of managing application state, where every possible action is defined beforehand and dispatched later on.

Usage

You might want to read the documentation, which also provides examples.

Also consider checking out the examples.

To run an example:

cargo run --example <name of the example>

To jump right into it, here is the simple counter example from examples/counter.rs:

use redux_rs::{Store, Subscription};

#[derive(Default)]
// This is a state. It describes an immutable object.
// It is changed via a 'reducer', a function which receives an action and returns a new state modified based on the action.
struct State {
    counter: i8
}

// The actions describe what the reducer has to do.
// Rust enums can carry a payload, which one can use to pass some value to the reducer.
enum Action {
    Increment,
    Decrement
}

// Here comes the reducer. It gets the current state plus an action to perform and returns a new state.
fn counter_reducer(state: &State, action: &Action) -> State {
    match action {
        Action::Increment => State {
            counter: state.counter + 1
        },
        Action::Decrement => State {
            counter: state.counter - 1
        }
    }
}

fn main() {
    // A store is a way to handle a state. It gets created once and after that it can be read and changed via dispatching actions.
    let mut store = Store::new(counter_reducer, State::default());

    // A listener getting triggered whenever the state changes.
    let listener: Subscription<State> = |state: &State| {
        println!("Counter changed! New value: {}", state.counter);
    };

    // Listener gets subscribed to the store.
    store.subscribe(listener);

    // Now, let's dispatch some actions!
    store.dispatch(Action::Increment);
    store.dispatch(Action::Increment);
    store.dispatch(Action::Increment);
    store.dispatch(Action::Decrement);
    store.dispatch(Action::Decrement);

    // Retrieve the value at any time.
    println!("Final value: {}", store.state().counter);
}

no_std support

redux-rs supports the no_std feature via disabling the default features.

Note: This requires a nightly compiler and the availability of the alloc crate for the target.

In your Cargo.toml:

[dependencies]
redux-rs = { version = "...", default-features = false }

Benchmarks

Running benchmarks requires a nightly compiler.

cargo +nightly bench
test counter_decrement                         ... bench:           2 ns/iter (+/- 0)
test counter_increment_with_reverse_middleware ... bench:           6 ns/iter (+/- 0)
test counter_increment_with_subscription       ... bench:           3 ns/iter (+/- 0)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].