0.2.2 • Published 10 years ago

generator-redux-component v0.2.2

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

generator-redux-component

Yeoman generator for React-Redux component. The code is written using ES7, so you need Babel for polyfill.

Installing the generator

$ npm install -g generator-redux-component

Usage

Run generator

yo redux-component

Choose component type (Smart or Dump)

Smart component

Reducers use Imutabale.js for state. I also use createReducers function for reduce boilerplate code.

import Immutable, { Map, List } from 'immutable';

export default function createReducer(initialState, handlers) {
  return (state = initialState, action) => {
    let newState = state;
    if (!Map.isMap(state) && !List.isList(state)) {
      newState = Immutable.fromJS(state);
    }

    const handler = handlers[action.type];

    if (!handler) {
      return newState;
    }

    newState = handler(newState, action);

    if (!Map.isMap(newState) && !List.isList(newState)) {
      throw new TypeError('Reducers must return Immutable objects.');
    }

    return newState;
  };
}

Don't forget to import generated reducer for createStore function!

Dump component

The dump component use BEM by default. You can find createBEM function here

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago