Commit 7c120bb4 by zhaochengxiang

防抖

parent 0767abb2
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { all, call, takeLatest, takeEvery, cancelled } from 'redux-saga/effects'
import { SetSource, Cancel } from '../util/axios'
import { all, call, takeLatest, takeEvery, delay } from 'redux-saga/effects'
import { Connect, showErrorNotifaction } from '../util';
import { reducers } from './reducer';
......@@ -15,9 +14,9 @@ const funcs = Connect({ user, datamodel, map, assetmanage, datasource })
function* request(args) {
const { type, payload, callback, error } = args.args;
SetSource();
try {
yield delay(300)
const rs = yield call(funcs[type], payload)
if (callback)
yield call(callback, rs)
......@@ -26,10 +25,6 @@ function* request(args) {
ex.ApiError && ex.ApiError.cnMessage && showErrorNotifaction('系统异常', ex.ApiError.cnMessage, 5);
error && error(ex);
}
}finally {
if (yield cancelled()) {
yield Cancel('cancel request');
}
}
}
......@@ -37,6 +32,10 @@ function* watchLatest() {
yield takeLatest('TAKE_LATEST', request)
}
function* watchLatestHomepage() {
yield takeLatest('TAKE_LATEST_HOMEPAGE', request);
}
function* watchEvery() {
yield takeEvery('TAKE_EVERY', request)
}
......@@ -49,13 +48,14 @@ export const store = createStore(
function* rootSaga() {
yield all([
watchLatest(), watchEvery()
watchLatest(), watchLatestHomepage(), watchEvery()
])
}
sagaMiddleware.run(rootSaga)
export const dispatchLatest = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_LATEST', args: { type, payload, callback, error } })
export const dispatchLatestHomepage = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_LATEST_HOMEPAGE', args: { type, payload, callback, error } })
export const dispatch = ({ type, payload=null, callback=null, error=null }) => store.dispatch({ type: 'TAKE_EVERY', args: { type, payload, callback, error } })
export const action = ({ type, args}) => store.dispatch({ type, args })
......@@ -14,7 +14,7 @@ import ImportAsset from './ImportAsset';
import AssetEdit from './AssetEdit';
import AssetDetail from "./AssetDetail";
import AssetItem from './AssetItem';
import { dispatch, dispatchLatest } from '../../../../model';
import { dispatch, dispatchLatestHomepage } from '../../../../model';
import { showMessage, showNotifaction, getQueryParam } from '../../../../util';
import { AnchorId, AnchorTimestamp } from '../../../../util/constant';
......@@ -141,7 +141,7 @@ const AssetTable = (props) => {
const getDataAssets = (elmentsGroup = filterElementsGroup) => {
setLoading(true);
dispatchLatest({
dispatchLatestHomepage({
type: 'assetmanage.listDataAssetsByPage',
payload: {
dirId: nodeId,
......
......@@ -4,7 +4,7 @@ import { DownOutlined, UpOutlined } from '@ant-design/icons';
import SmoothScroll from 'smooth-scroll';
import classnames from 'classnames';
import { dispatchLatest, dispatch } from '../../../../model';
import { dispatch } from '../../../../model';
import { showMessage, getQueryParam, paginate } from '../../../../util';
import { AnchorId, AnchorTimestamp, Action, CatalogId, ModelerId } from '../../../../util/constant';
......@@ -272,7 +272,7 @@ const ModelTable = (props) => {
title: '提示!',
content: `您确定要${action.cnName||''}该模型吗?`,
onOk: () => {
dispatchLatest({
dispatch({
type: 'datamodel.nextState',
payload: {
easyDataModelerDataModelId: record.id,
......@@ -311,7 +311,7 @@ const ModelTable = (props) => {
title: '提示!',
content: '您确定要删除该模型吗?',
onOk: () => {
dispatchLatest({
dispatch({
type: 'datamodel.deleteDataModel',
payload: {
params: {
......
......@@ -136,9 +136,9 @@ const VersionCompare = (props) => {
</Form.Item>
</Form>
<div className='py-3'>
<div className='py-5'>
<Spin spinning={loadingCompare} >
<div id="model-version-compare-container" style={{ }}></div>
<div id="model-version-compare-container"></div>
</Spin>
</div>
</div>
......
......@@ -14,7 +14,7 @@ import RecatalogModal from './Component/RecatalogModal';
import HistoryAndVersionDrawer from './Component/HistoryAndVersionDrawer';
import StartFlowModal from './Component/StartFlowModal';
import { showMessage, showNotifaction } from '../../../util';
import { dispatch, dispatchLatest } from '../../../model';
import { dispatch, dispatchLatestHomepage } from '../../../model';
import { Action, CatalogId, ModelerId, Hints, ModelerData, PermitCheckOut, Editable, StateId } from '../../../util/constant';
import { AppContext } from '../../../App';
......@@ -109,7 +109,7 @@ class Model extends React.Component {
this.setState({ loadingTableData: true }, () => {
if (keyword === '') {
if (currentView === 'dir') {
dispatch({
dispatchLatestHomepage({
type: 'datamodel.getCurrentDataModelCatalog',
payload: {
easyDataModelerCatalogId: catalogId,
......@@ -123,7 +123,7 @@ class Model extends React.Component {
}
})
} else {
dispatch({
dispatchLatestHomepage({
type: 'datamodel.getCurrentDataModelStateCatalog',
payload: {
easyDataModelerStateCatalogId: catalogId
......@@ -137,7 +137,7 @@ class Model extends React.Component {
})
}
} else {
dispatchLatest({
dispatchLatestHomepage({
type: 'datamodel.searchModel',
payload: {
term: keyword,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment