redux-eventually

0.0.2 • Public • Published

redux-eventually

Build Status npm npm

Redux-eventually facilitates using CRDTs inside of the redux store. This library consists of factory methods for easier usage with the otherwise quite cumbersome data-structures.

Example Counter

import { createCounterAction, createCounterReducer, createCounterSelector } from "redux-eventually";
 
const COUNTER = "COUNTER";
 
export countAction = createCounterAction(COUNTER);
/*
{
  type: COUNTER,
  payload: {
    id: "adam",
    value: 1
  }
}
*/
 
export counterReducer = createCounterReducer();
/*
{
  type: "pn-counter",
  p: {
    adam: 1,
    gustav: 0
  },
  n: {
    adam: 1,
    gustav: 1
  }
}
*/
 
export counterSelector = createCounterSelector();
 
let store = createStore(todosReducer);
const state = todosReducer(countAction("adam", 1));
const todos = todosSelector(state);

Example LSEQ

import { createEventualAction, lseq, createEventualReducer, createEventualSelector } from "redux-eventually";
 
const ADD_TODO = "ADD_TODO";
const REMOVE_TODO = "REMOVE_TODO";
 
// createEventualAction(actionType, operation)
export addTodoEventually = createEventualAction(ADD_TODO, lseq.LSEQ_INSERT);
 
export removeTodoEventually = createEventualAction(REMOVE_TODO, lseq.LSEQ_DELETE);
 
// createEventualReducer(stateConfig)
export todosReducer = createEventualReducer(lseq);
 
// eventualSelector returns a non-crdt representation
export todosSelector = createEventualSelector(lseq, state => state);
 
// Simple usage
let store = createStore(todosReducer);
const state = todosReducer(addTodoEventually("Buy flowers"));
const todos = todosSelector(state);

Package Sidebar

Install

npm i redux-eventually

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • gurre