Socket
Socket
Sign inDemoInstall

duxen

Package Overview
Dependencies
4
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    duxen

High performance engine maintaining a complex immutable state for online applications


Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Install size
2.45 MB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 23 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc