提交 2d960978 authored 作者: vipcxj's avatar vipcxj

improve: 改进错误警告,对连续的相同消息的警告弹出进行合并。

上级 8a3ce594
import React from 'react'; import React from 'react';
import { message, Modal } from 'antd'; import { message, Modal } from 'antd';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import memoize from 'lodash/memoize';
import { push } from '../services/route'; import { push } from '../services/route';
import { errors as errorCodes } from './config'; import { errors as errorCodes } from './config';
...@@ -13,9 +14,23 @@ const errStyle = { ...@@ -13,9 +14,23 @@ const errStyle = {
marginTop: '24px', marginTop: '24px',
}; };
const msgError = debounce((msg) => { function memDebounce(func, wait = 0, options = {}) {
const mem = memoize(() => {
const memFunc = (...args) => {
const ret = func(...args);
const { cache } = mem;
cache.delete(args[0]);
return ret;
};
// eslint-disable-next-line lodash-fp/no-extraneous-args
return debounce(memFunc, wait, options);
});
return (...args) => mem(...args)(...args);
}
const msgError = memDebounce((msg) => {
message.error(msg); message.error(msg);
}, 500); }, 300);
export function processError(err) { export function processError(err) {
if (err) { if (err) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论