A C++ implementation of the Redux library
All Redux-cpp source code is contained within a single header. The easiest way to install Redux-cpp is simply to drop it inside your project. Examples and unit tests can easiest be compiled with CMake. The respository has no dependencies except the standard library.
An implementation of the Redux Gist in Redux-cpp:
#include "redux.hpp"
#include <iostream>
enum Action {
INCREMENT,
DECREMENT
};
int reducer(int state, Action action) {
switch(action) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
default:
return state;
}
}
void log(int state) {
std::cout << state << std::endl;
}
int main() {
redux::Store<int, Action> store(reducer, 0);
store.subscribe(log);
store.dispatch(INCREMENT);
// 1
store.dispatch(INCREMENT);
// 2
store.dispatch(DECREMENT);
// 1
}