项目作者: tomsonTang

项目描述 :
redux-saga-model 的 loading 插件
高级语言: JavaScript
项目地址: git://github.com/tomsonTang/redux-saga-model-loading.git
创建时间: 2017-08-22T06:22:51Z
项目社区:https://github.com/tomsonTang/redux-saga-model-loading

开源协议:

下载


redux-saga-model-loading

redux-saga-model 的 loading 插件

install

  1. $ npm i redux-saga-model-loading

or

  1. $ yarn add redux-saga-model-loading

使用

index.js

  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import {Provider} from 'react-redux'
  4. import "antd/dist/antd.css";
  5. import loading from 'redux-saga-model-loading';
  6. import sagaModel from "reudx-saga-model";
  7. import Layout from "./view/Layout.jsx";
  8. import UsersTable from "./view/UsersTable.jsx";
  9. //加载插件
  10. sagaModel.use(loading);
  11. ReactDOM.render(
  12. <Provider store={sagaModel.store()}>
  13. <Layout>
  14. <UsersTable ></UsersTable>
  15. </Layout>
  16. </Provider>,
  17. document.querySelector("#root")
  18. );

component.js

  1. import React from "react";
  2. import { Table, Input, Icon, Button, Popconfirm } from "antd";
  3. import { connect } from "react-redux";
  4. import { bindActionCreators } from "redux";
  5. import { namespace as dbNamespace } from "../../db/dataModel.js";
  6. import * as action from "../../action.js";
  7. const columns = [
  8. //...
  9. ];
  10. class EditableTable extends React.Component {
  11. constructor(props) {}
  12. componentWillMount = () => {
  13. this.props.getUsers();
  14. };
  15. render() {
  16. const { dataSource,loading } = this.props;
  17. const columns = this.columns;
  18. return (
  19. <div>
  20. <Table bordered dataSource={dataSource} columns={columns} loading={loading}></Table>
  21. </div>
  22. );
  23. }
  24. }
  25. const mapDispatchToProps = dispatch => {
  26. return bindActionCreators(action, dispatch);
  27. };
  28. const mapStateToProps = state => {
  29. const usersState = state[dbNamespace];
  30. return {
  31. dataSource: usersState.list,
  32. count: usersState.count,
  33. // 获取对应 namespace 下的 loading 状态
  34. loading:state.loading.models[dbNamespace]
  35. };
  36. };
  37. export default connect(mapStateToProps, mapDispatchToProps)(EditableTable);

action.js

  1. import {LOADING,META} from 'redux-saga-model-loading'
  2. export const getUsers = ()=>{
  3. return {
  4. type:'users/db/getUsers',
  5. payload:{},
  6. //告诉插件为 users/db/getUsers 这个副作用开启 loading
  7. meta:META
  8. }
  9. }

其他

  1. 详细案例 redux-saga-model 在线案例
  2. 配合 redux-saga-model 使用指南