From 122e37422445d4826bbbdc32153f11c038242b9f Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 21 Sep 2020 21:48:12 +0800 Subject: [PATCH] perf: remove syncWatch --- components/_util/PortalWrapper.js | 5 ++--- components/_util/syncWatch.js | 6 ------ components/badge/ScrollNumber.jsx | 5 ++--- components/input/Input.jsx | 5 ++--- components/input/ResizableTextArea.jsx | 5 ++--- components/input/TextArea.jsx | 5 ++--- components/modal/Modal.jsx | 5 ++--- components/vc-cascader/Cascader.jsx | 9 ++++----- components/vc-table/src/Table.jsx | 5 ++--- components/vc-tree/src/Tree.jsx | 5 ++--- 10 files changed, 20 insertions(+), 35 deletions(-) delete mode 100644 components/_util/syncWatch.js diff --git a/components/_util/PortalWrapper.js b/components/_util/PortalWrapper.js index 84170c206..2ae3f6b29 100644 --- a/components/_util/PortalWrapper.js +++ b/components/_util/PortalWrapper.js @@ -2,7 +2,6 @@ import PropTypes from './vue-types'; import switchScrollingEffect from './switchScrollingEffect'; import setStyle from './setStyle'; import Portal from './Portal'; -import syncWatch from './syncWatch'; let openCount = 0; const windowIsUndefined = !( @@ -33,9 +32,9 @@ export default { this.setWrapperClassName(); }, watch: { - visible: syncWatch(function(val) { + visible(val) { openCount = val ? openCount + 1 : openCount - 1; - }), + }, getContainer(getContainer, prevGetContainer) { const getContainerIsFunc = typeof getContainer === 'function' && typeof prevGetContainer === 'function'; diff --git a/components/_util/syncWatch.js b/components/_util/syncWatch.js deleted file mode 100644 index aa2e25438..000000000 --- a/components/_util/syncWatch.js +++ /dev/null @@ -1,6 +0,0 @@ -export default function syncWatch(fn) { - return { - handler: fn, - flush: 'sync', - }; -} diff --git a/components/badge/ScrollNumber.jsx b/components/badge/ScrollNumber.jsx index f91f71d99..4fbcde2e2 100644 --- a/components/badge/ScrollNumber.jsx +++ b/components/badge/ScrollNumber.jsx @@ -5,7 +5,6 @@ import omit from 'omit.js'; import { cloneElement } from '../_util/vnode'; import { ConfigConsumerProps } from '../config-provider'; import { inject } from 'vue'; -import syncWatch from '../_util/syncWatch'; function getNumberArray(num) { return num @@ -47,12 +46,12 @@ export default { }; }, watch: { - count: syncWatch(function() { + count() { this.lastCount = this.sCount; this.setState({ animateStarted: true, }); - }), + }, }, updated() { const { animateStarted, count } = this; diff --git a/components/input/Input.jsx b/components/input/Input.jsx index f81c06c37..8c6a24700 100644 --- a/components/input/Input.jsx +++ b/components/input/Input.jsx @@ -6,7 +6,6 @@ import inputProps from './inputProps'; import { hasProp, getComponent, getOptionProps } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; import ClearableLabeledInput from './ClearableLabeledInput'; -import syncWatch from '../_util/syncWatch'; export function fixControlledValue(value) { if (typeof value === 'undefined' || value === null) { @@ -68,9 +67,9 @@ export default { }; }, watch: { - value: syncWatch(function(val) { + value(val) { this.stateValue = val; - }), + }, }, mounted() { this.$nextTick(() => { diff --git a/components/input/ResizableTextArea.jsx b/components/input/ResizableTextArea.jsx index 369d603d3..f99aa9459 100644 --- a/components/input/ResizableTextArea.jsx +++ b/components/input/ResizableTextArea.jsx @@ -8,7 +8,6 @@ import BaseMixin from '../_util/BaseMixin'; import inputProps from './inputProps'; import PropTypes from '../_util/vue-types'; import { getOptionProps } from '../_util/props-util'; -import syncWatch from '../_util/syncWatch'; const RESIZE_STATUS_NONE = 0; const RESIZE_STATUS_RESIZING = 1; @@ -39,11 +38,11 @@ const ResizableTextArea = { raf.cancel(this.resizeFrameId); }, watch: { - value: syncWatch(function() { + value() { this.$nextTick(() => { this.resizeTextarea(); }); - }), + }, }, methods: { saveTextArea(textArea) { diff --git a/components/input/TextArea.jsx b/components/input/TextArea.jsx index d85257ac7..870e0ff8a 100644 --- a/components/input/TextArea.jsx +++ b/components/input/TextArea.jsx @@ -6,7 +6,6 @@ import { hasProp, getOptionProps } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; import { fixControlledValue, resolveOnChange } from './Input'; import PropTypes from '../_util/vue-types'; -import syncWatch from '../_util/syncWatch'; const TextAreaProps = { ...inputProps, @@ -32,9 +31,9 @@ export default { }; }, watch: { - value: syncWatch(function(val) { + value(val) { this.stateValue = val; - }), + }, }, mounted() { this.$nextTick(() => { diff --git a/components/modal/Modal.jsx b/components/modal/Modal.jsx index fc8dbf50d..453b76ccb 100644 --- a/components/modal/Modal.jsx +++ b/components/modal/Modal.jsx @@ -11,7 +11,6 @@ const ButtonType = buttonTypes().type; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { initDefaultProps, getComponent, getSlot } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; -import syncWatch from '../_util/syncWatch'; let mousePosition = null; // ref: https://github.com/ant-design/ant-design/issues/15795 @@ -107,9 +106,9 @@ export default { }; }, watch: { - visible: syncWatch(function(val) { + visible(val) { this.sVisible = val; - }), + }, }, setup() { return { diff --git a/components/vc-cascader/Cascader.jsx b/components/vc-cascader/Cascader.jsx index ac9ded016..6146ecd33 100644 --- a/components/vc-cascader/Cascader.jsx +++ b/components/vc-cascader/Cascader.jsx @@ -8,7 +8,6 @@ import shallowEqualArrays from 'shallow-equal/arrays'; import { hasProp, getEvents } from '../_util/props-util'; import BaseMixin from '../_util/BaseMixin'; import { cloneElement } from '../_util/vnode'; -import syncWatch from '../_util/syncWatch'; const BUILT_IN_PLACEMENTS = { bottomLeft: { @@ -100,7 +99,7 @@ export default { }; }, watch: { - value: syncWatch(function(val, oldValue) { + value(val, oldValue) { if (!shallowEqualArrays(val, oldValue)) { const newValues = { sValue: val || [], @@ -112,12 +111,12 @@ export default { } this.setState(newValues); } - }), - popupVisible: syncWatch(function(val) { + }, + popupVisible(val) { this.setState({ sPopupVisible: val, }); - }), + }, }, methods: { getPopupDOMNode() { diff --git a/components/vc-table/src/Table.jsx b/components/vc-table/src/Table.jsx index ccd604ea7..b86594bef 100644 --- a/components/vc-table/src/Table.jsx +++ b/components/vc-table/src/Table.jsx @@ -15,7 +15,6 @@ import BodyTable from './BodyTable'; import ExpandableTable from './ExpandableTable'; import { initDefaultProps, getOptionProps } from '../../_util/props-util'; import BaseMixin from '../../_util/BaseMixin'; -import syncWatch from '../../_util/syncWatch'; export default { name: 'Table', @@ -129,11 +128,11 @@ export default { this.components, ); }, - columns: syncWatch(function(val) { + columns(val) { if (val) { this.columnManager.reset(val); } - }), + }, data(val) { if (val.length === 0 && this.hasScrollX()) { this.$nextTick(() => { diff --git a/components/vc-tree/src/Tree.jsx b/components/vc-tree/src/Tree.jsx index e7e32e7f0..7941d9682 100644 --- a/components/vc-tree/src/Tree.jsx +++ b/components/vc-tree/src/Tree.jsx @@ -4,7 +4,6 @@ import warning from 'warning'; import { hasProp, initDefaultProps, getOptionProps, getSlot } from '../../_util/props-util'; import { cloneElement } from '../../_util/vnode'; import BaseMixin from '../../_util/BaseMixin'; -import syncWatch from '../../_util/syncWatch'; import { convertTreeToEntities, convertDataToTree, @@ -153,10 +152,10 @@ const Tree = { 'checkedKeys', 'loadedKeys', ]), - __propsSymbol__: syncWatch(function() { + __propsSymbol__() { this.setState(this.getDerivedState(getOptionProps(this), this.$data)); this.needSyncKeys = {}; - }), + }, }, methods: {