Skip to content

sutbult/redux-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redux-cpp

A C++ implementation of the Redux library

Build Status

Installation

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.

The Gist

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
}

About

Predictable state container for C++ apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published