项目作者: shoponpon

项目描述 :
flux templete generator
高级语言: JavaScript
项目地址: git://github.com/shoponpon/flux-gen.git
创建时间: 2018-05-30T06:01:31Z
项目社区:https://github.com/shoponpon/flux-gen

开源协议:

下载


flux-gen[WIP]

flux component generator

This generator generates some templates for facebook/flux component.

Installation

  1. $ npm install -g https://github.com/shoponpon/flux-gen.git

How to use

Generate templetes of Actions.js and ActionTypes.js

  1. $ flux-gen action [actionname] [dispatcherPath]

Generate a templete of Dispatcher.js

  1. $ flux-gen dispatcher

Generate a templete of Store.js

  1. $ flux-gen action [storename] [dispatcherPath]

Examples

Actions.js and ActionTypes.js

command

  1. $ flux-gen action image ./Dispatcher.js

output

  • ImageActions.js
  1. import ImageActionTypes from './ImageActionTypes'
  2. import Dispatcher from './Dispatcher'
  3. const ImageActions = {}
  4. export default ImageActions
  • ImageActionTypes.js
  1. const ImageActionTypes = {}
  2. export default ImageActionTypes

Store.js

command

  1. $ flux-gen store image ./Dispatcher.js

output

  • ImageStore.js
  1. import { ReduceStore } from 'flux/utils'
  2. import Dispatcher from './Dispatcher'
  3. class ImageStore extends ReduceStore {
  4. constructor() {
  5. super(Dispatcher)
  6. }
  7. getInitialState() {
  8. return {}
  9. }
  10. reduce(state, action) {
  11. switch (action.type) {
  12. default:
  13. break
  14. }
  15. return Object.assign({}, state)
  16. }
  17. }
  18. export default new ImageStore()

Dispatcher.js

command

  1. $ flux-gen dispatcher

output

  • Dispatcher.js
    1. import { Dispatcher } from 'flux'
    2. export default new Dispatcher()

ToDo

  • Action Generator
  • Store Generator
  • Dispatcher Generator
  • Container Generator
  • Refactoring