app-universe

Crates.ioapp-universe
lib.rsapp-universe
version1.0.0
sourcesrc
created_at2022-11-10 22:51:31.094185
updated_at2023-11-21 21:32:15.540327
descriptionA framework agnostic approach to managing frontend application state.
homepage
repositoryhttps://github.com/AkinAguda/app-universe
max_upload_size
id712453
size16,927
Akinwunmi Aguda (AkinAguda)

documentation

https://docs.rs/app_universe

README

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();
}

Inspiration

Commit count: 54

cargo fmt