opensupports-redux-classes

1.0.0 • Public • Published

opensupports-redux-classes

This is an utility for having reducers as classes in a Redux architecture.

Usage

const { Reducer } = require('opensupports-redux-classes');

class MyReducer extends Reducer {
    getInitialState() {
        return {
            opened: false
        };
    }

    getTypeHandlers() {
        return {
            'OPEN': this.handleOpen.bind(this),
            'CLOSE': this.handleClose.bind(this)
        };
    }

    handleOpen(state) {
        return {
            ...state,
            opened: true
        };
    }

    handleClose(state) {
        return {
            ...state,
            opened: false
        };
    }
}

module.exports = MyReducer.getInstance();

This will export a reducer that:

  • Its initial state is opened: false
  • When 'OPEN' action happens, it replaces the state it with opened: true
  • When 'CLOSE' action happens, it replaces the state it with opened: false

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i opensupports-redux-classes

      Weekly Downloads

      1

      Version

      1.0.0

      License

      ISC

      Unpacked Size

      1.8 kB

      Total Files

      4

      Last publish

      Collaborators

      • ivandiazwm