7 releases (1 stable)
1.0.0 | Nov 21, 2023 |
---|---|
0.2.1 | Nov 26, 2022 |
0.1.3 | Nov 13, 2022 |
#9 in #redux
16KB
157 lines
App-Universe
A framework agnostic approach to managing frontend application state based on app-world.
Example Usage
mod app_universe;
use app_universe::{ AppUniverse, AppUniverseCore };
struct TestAppState {
counter: u8,
}
pub enum Msg {
Increment(u8),
}
impl AppUniverseCore for TestAppState {
type Message = Msg;
fn msg(&mut self, message: Self::Message) {
match message {
Msg::Increment(value) => {
self.counter += value;
}
}
}
}
fn main () {
let state = TestAppState { counter: 0 };
let mut universe = AppUniverse::new(state);
universe.msg(Msg::Increment(1));
let subscription = universe.subscribe(Box::new(move |universe| {
println!("Counter value is {}", universe.read().counter);
}));
universe.msg(Msg::Increment(1));
universe.unsubscribe(subscription).unwrap();
}