reduxed 0.0.3

A redux/flux like store in D


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

reduxed

A library implementing the redux pattern in the D Progamming Language. ArchDiagram

When should you use reduxed?

The redux pattern helps, when an application has shared state that needs to be observed and manipulated by multiple parts of the application. Additionally, using pure reducer functions makes it easy to test state transitions.

Examples

// Define your store as a struct
struct Bar {
	int b;
	int a;
}

// Create the store
Store!Bar store;
// set store init values
store.a = 1;
store.b = 2;

int a = 1337;

// We use this function to observe Bar.a
void fun(ref const(int) f) @safe {
	a = f;
}

// Here we subscribe to Bar.a
// Whenever Bar.a changes "fun" gets called
store.a.subscribe(&fun);

// This function is used to change the value
static int increment(int a, int b) pure {
	return a + b; 
}

// Here we call increment with the values of store.a and store.b
// the effect is equal to
// store.a = increment(store.a, store.b);
store.execute!(increment)(store.a, store.b);

assert(store.a.value == 3);
assert(a == 3);
Authors:
  • burner
Dependencies:
none
Versions:
0.0.3 2018-Aug-23
0.0.2 2018-Aug-21
0.0.1 2018-Aug-21
~master 2018-Aug-23
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Score:
0.4
Short URL:
reduxed.dub.pm