View on GitHub

tangdao

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

通过 . 的方式进行具体 model 下的 action 派发,具体如下:

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, dispatch } from '@maoyan/tangdao';

function App(props) {
  const { count } = props;
  return (
    <div>
      当前计数器为:{count}
      <button onClick={() => { dispatch.count.add(1); }}>increment</button>
      <button onClick={() => { dispatch.count.asyncAdd(1); }}>asyncAdd</button>
    </div>
  )
}