Skip to content

Commit 20ff341

Browse files
committed
perf: update listeners
1 parent 594dc07 commit 20ff341

File tree

8 files changed

+40
-27
lines changed

8 files changed

+40
-27
lines changed

components/radio/RadioButton.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Radio from './Radio';
2-
import PropTypes from '../_util/vue-types';
3-
import { getOptionProps } from '../_util/props-util';
2+
import { getOptionProps, getListeners } from '../_util/props-util';
43
import { ConfigConsumerProps } from '../config-provider';
54

65
export default {
@@ -22,7 +21,7 @@ export default {
2221
...otherProps,
2322
prefixCls,
2423
},
25-
on: { ...this.$listeners },
24+
on: getListeners(this),
2625
};
2726
if (this.radioGroupContext) {
2827
radioProps.on.change = this.radioGroupContext.onRadioChange;

components/slider/index.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from '../_util/vue-types';
22
import BaseMixin from '../_util/BaseMixin';
3-
import { getOptionProps } from '../_util/props-util';
3+
import { getOptionProps, getListeners } from '../_util/props-util';
44
import VcSlider from '../vc-slider/src/Slider';
55
import VcRange from '../vc-slider/src/Range';
66
import VcHandle from '../vc-slider/src/Handle';
@@ -117,6 +117,7 @@ const Slider = {
117117
const getPrefixCls = this.configProvider.getPrefixCls;
118118
const prefixCls = getPrefixCls('slider', customizePrefixCls);
119119
const tooltipPrefixCls = getPrefixCls('tooltip', customizeTooltipPrefixCls);
120+
const listeners = getListeners(this);
120121
if (range) {
121122
const vcRangeProps = {
122123
props: {
@@ -126,7 +127,7 @@ const Slider = {
126127
handle: info => this.handleWithTooltip(tooltipPrefixCls, info),
127128
},
128129
ref: 'sliderRef',
129-
on: this.$listeners,
130+
on: listeners,
130131
};
131132
return <VcRange {...vcRangeProps} />;
132133
}
@@ -138,7 +139,7 @@ const Slider = {
138139
handle: info => this.handleWithTooltip(tooltipPrefixCls, info),
139140
},
140141
ref: 'sliderRef',
141-
on: this.$listeners,
142+
on: listeners,
142143
};
143144
return <VcSlider {...vcSliderProps} />;
144145
},

components/tabs/tabs.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import VcTabs, { TabPane } from '../vc-tabs/src';
33
import TabContent from '../vc-tabs/src/TabContent';
44
import { isFlexSupported } from '../_util/styleChecker';
55
import PropTypes from '../_util/vue-types';
6-
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util';
6+
import {
7+
getComponentFromProp,
8+
getOptionProps,
9+
filterEmpty,
10+
getListeners,
11+
} from '../_util/props-util';
712
import { cloneElement } from '../_util/vnode';
813
import { ConfigConsumerProps } from '../config-provider';
914
import TabBar from './TabBar';
@@ -139,14 +144,15 @@ export default {
139144
) : null;
140145

141146
const renderTabBarSlot = renderTabBar || this.$scopedSlots.renderTabBar;
147+
const listeners = getListeners(this);
142148
const tabBarProps = {
143149
props: {
144150
...this.$props,
145151
prefixCls,
146152
tabBarExtraContent,
147153
renderTabBar: renderTabBarSlot,
148154
},
149-
on: this.$listeners,
155+
on: listeners,
150156
};
151157
const contentCls = {
152158
[`${prefixCls}-${tabPosition}-content`]: true,
@@ -165,7 +171,7 @@ export default {
165171
__propsSymbol__: Symbol(),
166172
},
167173
on: {
168-
...this.$listeners,
174+
...listeners,
169175
change: this.handleChange,
170176
},
171177
class: cls,

components/tree/DirectoryTree.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Tree, { TreeProps } from './Tree';
77
import { calcRangeKeys, getFullKeyList } from './util';
88
import Icon from '../icon';
99
import BaseMixin from '../_util/BaseMixin';
10-
import { initDefaultProps, getOptionProps } from '../_util/props-util';
10+
import { initDefaultProps, getOptionProps, getListeners } from '../_util/props-util';
1111
import { ConfigConsumerProps } from '../config-provider';
1212

1313
// export type ExpandAction = false | 'click' | 'dblclick'; export interface
@@ -186,10 +186,8 @@ export default {
186186
const getPrefixCls = this.configProvider.getPrefixCls;
187187
const prefixCls = getPrefixCls('tree', customizePrefixCls);
188188
const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data;
189-
warning(
190-
!this.$listeners.doubleclick,
191-
'`doubleclick` is deprecated. please use `dblclick` instead.',
192-
);
189+
const listeners = getListeners(this);
190+
warning(!listeners.doubleclick, '`doubleclick` is deprecated. please use `dblclick` instead.');
193191
const treeProps = {
194192
props: {
195193
icon: getIcon,
@@ -201,7 +199,7 @@ export default {
201199
ref: 'tree',
202200
class: `${prefixCls}-directory`,
203201
on: {
204-
...omit(this.$listeners, ['update:selectedKeys']),
202+
...omit(listeners, ['update:selectedKeys']),
205203
select: this.onSelect,
206204
click: this.onClick,
207205
dblclick: this.onDoubleClick,

components/upload/Upload.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import uniqBy from 'lodash/uniqBy';
33
import findIndex from 'lodash/findIndex';
44
import VcUpload from '../vc-upload';
55
import BaseMixin from '../_util/BaseMixin';
6-
import { getOptionProps, initDefaultProps, hasProp } from '../_util/props-util';
6+
import { getOptionProps, initDefaultProps, hasProp, getListeners } from '../_util/props-util';
77
import LocaleReceiver from '../locale-provider/LocaleReceiver';
88
import defaultLocale from '../locale-provider/default';
99
import { ConfigConsumerProps } from '../config-provider';
@@ -212,8 +212,9 @@ export default {
212212
remove: this.handleManualRemove,
213213
},
214214
};
215-
if (this.$listeners.preview) {
216-
uploadListProps.on.preview = this.$listeners.preview;
215+
const listeners = getListeners(this);
216+
if (listeners.preview) {
217+
uploadListProps.on.preview = listeners.preview;
217218
}
218219
return <UploadList {...uploadListProps} />;
219220
},

components/vc-align/Align.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import addEventListener from '../_util/Dom/addEventListener';
44
import { isWindow, buffer, isSamePoint, isSimilarValue, restoreFocus } from './util';
55
import { cloneElement } from '../_util/vnode.js';
66
import clonedeep from 'lodash/cloneDeep';
7-
import { getSlot } from '../_util/props-util';
7+
import { getSlot, getListeners } from '../_util/props-util';
88

99
function getElement(func) {
1010
if (typeof func !== 'function' || !func) return null;
@@ -117,7 +117,7 @@ export default {
117117
const { disabled, target, align } = this.$props;
118118
if (!disabled && target) {
119119
const source = this.$el;
120-
120+
const listeners = getListeners(this);
121121
let result;
122122
const element = getElement(target);
123123
const point = getPoint(target);
@@ -133,7 +133,7 @@ export default {
133133
}
134134
restoreFocus(activeElement, source);
135135
this.aligned = true;
136-
this.$listeners.align && this.$listeners.align(source, result);
136+
listeners.align && listeners.align(source, result);
137137
}
138138
},
139139
},

components/vc-tooltip/Tooltip.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PropTypes from '../_util/vue-types';
22
import Trigger from '../vc-trigger';
33
import { placements } from './placements';
44
import Content from './Content';
5-
import { hasProp, getComponentFromProp, getOptionProps } from '../_util/props-util';
5+
import { hasProp, getComponentFromProp, getOptionProps, getListeners } from '../_util/props-util';
66
function noop() {}
77
export default {
88
props: {
@@ -69,6 +69,7 @@ export default {
6969
if (hasProp(this, 'visible')) {
7070
extraProps.popupVisible = this.$props.visible;
7171
}
72+
const listeners = getListeners(this);
7273
const triggerProps = {
7374
props: {
7475
popupClassName: overlayClassName,
@@ -89,9 +90,9 @@ export default {
8990
...extraProps,
9091
},
9192
on: {
92-
...this.$listeners,
93-
popupVisibleChange: this.$listeners.visibleChange || noop,
94-
popupAlign: this.$listeners.popupAlign || noop,
93+
...listeners,
94+
popupVisibleChange: listeners.visibleChange || noop,
95+
popupAlign: listeners.popupAlign || noop,
9596
},
9697
ref: 'trigger',
9798
};

components/vc-trigger/Trigger.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import Vue from 'vue';
22
import ref from 'vue-ref';
33
import PropTypes from '../_util/vue-types';
44
import contains from '../_util/Dom/contains';
5-
import { hasProp, getComponentFromProp, getEvents, filterEmpty } from '../_util/props-util';
5+
import {
6+
hasProp,
7+
getComponentFromProp,
8+
getEvents,
9+
filterEmpty,
10+
getListeners,
11+
} from '../_util/props-util';
612
import { requestAnimationTimeout, cancelAnimationTimeout } from '../_util/requestAnimationTimeout';
713
import addEventListener from '../_util/Dom/addEventListener';
814
import warning from '../_util/warning';
@@ -448,7 +454,8 @@ export default {
448454
sPopupVisible,
449455
});
450456
}
451-
this.$listeners.popupVisibleChange && this.$listeners.popupVisibleChange(sPopupVisible);
457+
const listeners = getListeners(this);
458+
listeners.popupVisibleChange && listeners.popupVisibleChange(sPopupVisible);
452459
}
453460
// Always record the point position since mouseEnterDelay will delay the show
454461
if (sPopupVisible && alignPoint && event) {

0 commit comments

Comments
 (0)