View on GitHub

tangdao

唐刀是一款基于 redux + redux-saga 以 model 为核心的数据流管理工具,它将 store 和 saga 统一为 model 的概念,写在一个 js 文件中,以对象配置的概念维护 state、 reducers、effects 等。

通过 . 的方式获取具体 model 下的 actionCreator,具体如下:

model

const count = {
  namespace: 'count',
  state: 0,
  reducers: {
    add(state, { payload }) {
      return state + payload;
    }
  }
  effects: {
    * asyncAdd({ payload }, { put }, actionCreator) {
      yield new Promise(resolve => setTimeout(resolve, 1000));
      yield put(actionCreator.add(payload));
    }
  }
}

组件

import React from 'react';
import { connect, actionCreator } from '@maoyan/tangdao';

console.log(actionCreator);
/* 输出
{
  add: function(payload) {
  	return {
  		type: 'count/add',
  		payload
  	}
  },
  asyncAdd: function(payload){
    return {
      type: 'count/effect/asyncAdd',
      payload
    }
  }  
}
/*