0.8.8 • Published 5 years ago

duxen v0.8.8

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

duxen

DUXEN

npm version jest dependencies devDependencies Gitter License: MIT

High performance data engine maintaining complex immutable state for reactive applications. Fully integrated with Immutable.js, Redux, and Meteor.

See demo here: https://stackblitz.com/edit/duxen-demo

Huh?

Redux is an amazing concept that shows how to manage application data in a predictable state containers. It is actually a tiny library (2kB) with a simple container that receives actions and forwards them to reducers. The actions and reducers themselves have to be fully designed and developed from scratch. Although Redux applications are elegant, behave consistently, and are easy to test, their state management logic is usually scattered across many small files and developers may end up typing a lot of repetitive boilerplate code. Moreover, the reducers must be written as pure functions with no side effects and they have to modify the application state in an immutable way. This can become difficult and error prone especially if application logic is complex.

So here comes DUXEN, the Redux Engine.

Instead of writing individual reducers and action creators, the developer is focusing on the whole application state. The state is described with a schema that contains simple values, collections, and views which are seamlessly transforming the data in collections into their presentation form. The DUXEN compiles the schema, generates the reducers, and provides all the action creators. The resulting application state is built by DUXEN as one large immutable object using Immutable.js library.

Installation

npm install duxen

Development

Setup:

git clone https://github.com/applitopia/duxen.git
cd duxen
npm install

Lint:

npm run lint

Build:

npm run build

Test:

npm test

Lint, Build, & Test:

npm run all

Update Dependencies:

npm update --save

Example

Define your DUXEN schema:

const cmp=(a,b)=>(a>b?1:(a<b?-1:0))

const schema = {

  'todosFilter': {
    type: 'value',
    initValue: "",
  },

  'todosLimit': {
    type: 'value',
    initValue: 10,
  },

  'todos': {type: 'collection'},

  'todosView': {
    type:'view',
    sourceName: 'todos',
    props: ['todosFilter', 'todosLimit'],
    recipe: (seq, props)=>seq
      .filter(v=>v.get('text').indexOf(props.todosFilter) >= 0)
      .sort((a, b)=>cmp(a.get('text'), b.get('text')))
      .take(props.todosLimit),
  },

  'todosCnt': {
    type:'view',
    sourceName: 'todosView',
    props: [],
    recipe: (seq)=>Seq({cnt: seq.count()})
  },

  'todosCompletedCnt': {
    type:'view',
    sourceName: 'todosView',
    props: [],
    recipe: (seq, props)=>{
      const cnt = seq
      .filter(v=>v.get('completed'))
      .count();
      return Seq({cnt});
    }
  },

}

Create a DUXEN engine:

import { createEngine } from 'duxen'

const engine = createEngine(schema)

Get a reducer from the engine and attach it to a Redux store:

import { createStore } from 'redux'

const store = createStore(engine.reducer())

Create actions and dispatch them to the store:

// Create an action that changes the value of the filter
const action = engine.value('todosFilter', "Get milk");

// Dispatch the action to the Redux store
store.dispatch(action);

// Get the updated state from the store
const state = store.getState();

License

MIT

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago