14 releases (breaking)

0.12.0 Nov 11, 2024
0.10.4 Oct 9, 2024
0.9.0 Jul 3, 2024

#199 in Concurrency

Download history 69/week @ 2024-07-29 31/week @ 2024-08-05 322/week @ 2024-08-12 32/week @ 2024-08-19 61/week @ 2024-08-26 52/week @ 2024-09-02 28/week @ 2024-09-09 25/week @ 2024-09-16 62/week @ 2024-09-23 74/week @ 2024-09-30 207/week @ 2024-10-07 223/week @ 2024-10-14 24/week @ 2024-10-21 17/week @ 2024-10-28 81/week @ 2024-11-04 179/week @ 2024-11-11

322 downloads per month

Custom license

52KB
1.5K SLoC

rs-store

rs-store is a Redux Store written in Rust.

Key Features

Manage and receive notifications of state changes through the Reducer and Subscriber interfaces. Store registers Reducer and Subscriber, dispatches actions to change the state, and sends notifications to subscribers. Store is designed to change states in thread-safe manner.

How to use

rust documentation is available at crates.io and docs.rs.


pub fn main() {
    println!("Hello, Calc!");

    let store = Store::<CalcState, CalcAction>::new(Box::new(CalcReducer::default()));

    store.add_subscriber(Arc::new(CalcSubscriber::default()));
    store.dispatch(CalcAction::Add(1));

    thread::sleep(std::time::Duration::from_secs(1));
    store.add_subscriber(Arc::new(CalcSubscriber::default()));
    store.dispatch(CalcAction::Subtract(1));

    store.stop();
}

Features

  • add thread name
  • subscription to unsubscribe
  • clear subscribers (clear_subscribers)
  • add Thunk action(dispatch_thunk)
  • notify the latest state when a subscriber added
  • add backpressure policy(drop oldest)
  • bounding channel size(sync_channel), dispatch can be failed
  • add scheduler for notification(CurrentThread, ThreadPool)
  • stream (pull model) instead of subscription(push model)
  • stats middleware which can be used to log the state changes
  • add tests

Dependencies

~0.3–0.8MB
~18K SLoC