Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Mas

a C++ port of redux library with some custom features.

#include<mas/store.h>structState {
int id = 1;
};
structAction {
std::string event;
};
auto reducer = [](const State& state, const Action& action) -> State {
State new_state = state;
if (action.event == "add") {
new_state.id++;
} elseif (action.event == "subtract") {
new_state.id--;
}
return new_state;
};
intmain(int argc, char** argv) {
using mas::SimpleStore;
State s;
SimpleStore<State, Action> store(s, reducer);
store.subscribe("add", [](const State& s) {
std::cout << "receiver 1, receive add event" << std::endl;
return0;
});
store.subscribe("add", [](const State& s) {
std::cout << "receiver 2, receive add event" << std::endl;
return0;
});
store.subscribe("subtract", [](const State& s) {
std::cout << "receiver 3, receive subtract event" << std::endl;
return0;
});
Action action;
{
action.event = "add";
store.dispatch(action, "add");
auto& state = store.state();
std::cout << "state id:" << state.id << std::endl;
}
{
action.event = "subtract";
store.dispatch(action, [](const Action& a) { return a.event; });
auto& state = store.state();
std::cout << "state id:" << state.id << std::endl;
}
return0;
}

License

MIT License

About

a state management library.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages