Giter Site home page Giter Site logo

dux's Introduction

Dux for Redux

npm i --save redux-dux

This is a tiny utility for creating Redux modules.

Benefits

  • Isolates state of the module, reduce function may update only related slice of the state.
  • No need to care about action and action types, these are abstracted away.

Why

I had a need for a succinct way to define a redux module and express dependencies between modules.

Example

import { createStore, dux, update } from 'redux-dux';

const store = createStore(s => s);

const grid = dux(
    {
      setRows: (state, rows, total) => {
        return update(state, {
          rows,
          total
        });
      },
      selectRow: (state, index) => {
        return update(state, {
          selected: state.rows[index]
        });
      }
    },
    {
      rows: state => state.rows,
      total: state => state.total,
      selected: state => state.selected
    }
  );

grid.setRows([{ a: 1 }, { b: 2 }], 1000);
console.log(grid.selectors.rows(store.getState())) // [{ a: 1 }, { b: 2 }]

dux.update : function

Object immutability helper. See update-js.

Kind: static constant of dux

dux.dux(options)

Creates a Redux module.

Kind: static method of dux

Param Type Description
options Object set of key-value pairs, where key is an action creator name and value is a reducer function. The reducer function receives a slice of the state, corresponding to the module, and arguments passed to the action creator: (slice, ...args). The reducer function can return either a new slice or a function which receives the whole state and returns a new slice.

dux.createStore()

Creates Redux store. See createStore.md.

Kind: static method of dux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.