Crates.io | app-universe |
lib.rs | app-universe |
version | 1.0.0 |
source | src |
created_at | 2022-11-10 22:51:31.094185 |
updated_at | 2023-11-21 21:32:15.540327 |
description | A framework agnostic approach to managing frontend application state. |
homepage | |
repository | https://github.com/AkinAguda/app-universe |
max_upload_size | |
id | 712453 |
size | 16,927 |
A framework agnostic approach to managing frontend application state based on app-world.
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();
}