perf: update listeners

pull/1741/head
tangjinzhou 2020-01-18 21:44:13 +08:00
parent 594dc07dff
commit 20ff3419e7
8 changed files with 40 additions and 27 deletions

View File

@ -1,6 +1,5 @@
import Radio from './Radio'; import Radio from './Radio';
import PropTypes from '../_util/vue-types'; import { getOptionProps, getListeners } from '../_util/props-util';
import { getOptionProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
export default { export default {
@ -22,7 +21,7 @@ export default {
...otherProps, ...otherProps,
prefixCls, prefixCls,
}, },
on: { ...this.$listeners }, on: getListeners(this),
}; };
if (this.radioGroupContext) { if (this.radioGroupContext) {
radioProps.on.change = this.radioGroupContext.onRadioChange; radioProps.on.change = this.radioGroupContext.onRadioChange;

View File

@ -1,6 +1,6 @@
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { getOptionProps } from '../_util/props-util'; import { getOptionProps, getListeners } from '../_util/props-util';
import VcSlider from '../vc-slider/src/Slider'; import VcSlider from '../vc-slider/src/Slider';
import VcRange from '../vc-slider/src/Range'; import VcRange from '../vc-slider/src/Range';
import VcHandle from '../vc-slider/src/Handle'; import VcHandle from '../vc-slider/src/Handle';
@ -117,6 +117,7 @@ const Slider = {
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('slider', customizePrefixCls); const prefixCls = getPrefixCls('slider', customizePrefixCls);
const tooltipPrefixCls = getPrefixCls('tooltip', customizeTooltipPrefixCls); const tooltipPrefixCls = getPrefixCls('tooltip', customizeTooltipPrefixCls);
const listeners = getListeners(this);
if (range) { if (range) {
const vcRangeProps = { const vcRangeProps = {
props: { props: {
@ -126,7 +127,7 @@ const Slider = {
handle: info => this.handleWithTooltip(tooltipPrefixCls, info), handle: info => this.handleWithTooltip(tooltipPrefixCls, info),
}, },
ref: 'sliderRef', ref: 'sliderRef',
on: this.$listeners, on: listeners,
}; };
return <VcRange {...vcRangeProps} />; return <VcRange {...vcRangeProps} />;
} }
@ -138,7 +139,7 @@ const Slider = {
handle: info => this.handleWithTooltip(tooltipPrefixCls, info), handle: info => this.handleWithTooltip(tooltipPrefixCls, info),
}, },
ref: 'sliderRef', ref: 'sliderRef',
on: this.$listeners, on: listeners,
}; };
return <VcSlider {...vcSliderProps} />; return <VcSlider {...vcSliderProps} />;
}, },

View File

@ -3,7 +3,12 @@ import VcTabs, { TabPane } from '../vc-tabs/src';
import TabContent from '../vc-tabs/src/TabContent'; import TabContent from '../vc-tabs/src/TabContent';
import { isFlexSupported } from '../_util/styleChecker'; import { isFlexSupported } from '../_util/styleChecker';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { getComponentFromProp, getOptionProps, filterEmpty } from '../_util/props-util'; import {
getComponentFromProp,
getOptionProps,
filterEmpty,
getListeners,
} from '../_util/props-util';
import { cloneElement } from '../_util/vnode'; import { cloneElement } from '../_util/vnode';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import TabBar from './TabBar'; import TabBar from './TabBar';
@ -139,6 +144,7 @@ export default {
) : null; ) : null;
const renderTabBarSlot = renderTabBar || this.$scopedSlots.renderTabBar; const renderTabBarSlot = renderTabBar || this.$scopedSlots.renderTabBar;
const listeners = getListeners(this);
const tabBarProps = { const tabBarProps = {
props: { props: {
...this.$props, ...this.$props,
@ -146,7 +152,7 @@ export default {
tabBarExtraContent, tabBarExtraContent,
renderTabBar: renderTabBarSlot, renderTabBar: renderTabBarSlot,
}, },
on: this.$listeners, on: listeners,
}; };
const contentCls = { const contentCls = {
[`${prefixCls}-${tabPosition}-content`]: true, [`${prefixCls}-${tabPosition}-content`]: true,
@ -165,7 +171,7 @@ export default {
__propsSymbol__: Symbol(), __propsSymbol__: Symbol(),
}, },
on: { on: {
...this.$listeners, ...listeners,
change: this.handleChange, change: this.handleChange,
}, },
class: cls, class: cls,

View File

@ -7,7 +7,7 @@ import Tree, { TreeProps } from './Tree';
import { calcRangeKeys, getFullKeyList } from './util'; import { calcRangeKeys, getFullKeyList } from './util';
import Icon from '../icon'; import Icon from '../icon';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { initDefaultProps, getOptionProps } from '../_util/props-util'; import { initDefaultProps, getOptionProps, getListeners } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
// export type ExpandAction = false | 'click' | 'dblclick'; export interface // export type ExpandAction = false | 'click' | 'dblclick'; export interface
@ -186,10 +186,8 @@ export default {
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('tree', customizePrefixCls); const prefixCls = getPrefixCls('tree', customizePrefixCls);
const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data; const { _expandedKeys: expandedKeys, _selectedKeys: selectedKeys } = this.$data;
warning( const listeners = getListeners(this);
!this.$listeners.doubleclick, warning(!listeners.doubleclick, '`doubleclick` is deprecated. please use `dblclick` instead.');
'`doubleclick` is deprecated. please use `dblclick` instead.',
);
const treeProps = { const treeProps = {
props: { props: {
icon: getIcon, icon: getIcon,
@ -201,7 +199,7 @@ export default {
ref: 'tree', ref: 'tree',
class: `${prefixCls}-directory`, class: `${prefixCls}-directory`,
on: { on: {
...omit(this.$listeners, ['update:selectedKeys']), ...omit(listeners, ['update:selectedKeys']),
select: this.onSelect, select: this.onSelect,
click: this.onClick, click: this.onClick,
dblclick: this.onDoubleClick, dblclick: this.onDoubleClick,

View File

@ -3,7 +3,7 @@ import uniqBy from 'lodash/uniqBy';
import findIndex from 'lodash/findIndex'; import findIndex from 'lodash/findIndex';
import VcUpload from '../vc-upload'; import VcUpload from '../vc-upload';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { getOptionProps, initDefaultProps, hasProp } from '../_util/props-util'; import { getOptionProps, initDefaultProps, hasProp, getListeners } from '../_util/props-util';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default'; import defaultLocale from '../locale-provider/default';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
@ -212,8 +212,9 @@ export default {
remove: this.handleManualRemove, remove: this.handleManualRemove,
}, },
}; };
if (this.$listeners.preview) { const listeners = getListeners(this);
uploadListProps.on.preview = this.$listeners.preview; if (listeners.preview) {
uploadListProps.on.preview = listeners.preview;
} }
return <UploadList {...uploadListProps} />; return <UploadList {...uploadListProps} />;
}, },

View File

@ -4,7 +4,7 @@ import addEventListener from '../_util/Dom/addEventListener';
import { isWindow, buffer, isSamePoint, isSimilarValue, restoreFocus } from './util'; import { isWindow, buffer, isSamePoint, isSimilarValue, restoreFocus } from './util';
import { cloneElement } from '../_util/vnode.js'; import { cloneElement } from '../_util/vnode.js';
import clonedeep from 'lodash/cloneDeep'; import clonedeep from 'lodash/cloneDeep';
import { getSlot } from '../_util/props-util'; import { getSlot, getListeners } from '../_util/props-util';
function getElement(func) { function getElement(func) {
if (typeof func !== 'function' || !func) return null; if (typeof func !== 'function' || !func) return null;
@ -117,7 +117,7 @@ export default {
const { disabled, target, align } = this.$props; const { disabled, target, align } = this.$props;
if (!disabled && target) { if (!disabled && target) {
const source = this.$el; const source = this.$el;
const listeners = getListeners(this);
let result; let result;
const element = getElement(target); const element = getElement(target);
const point = getPoint(target); const point = getPoint(target);
@ -133,7 +133,7 @@ export default {
} }
restoreFocus(activeElement, source); restoreFocus(activeElement, source);
this.aligned = true; this.aligned = true;
this.$listeners.align && this.$listeners.align(source, result); listeners.align && listeners.align(source, result);
} }
}, },
}, },

View File

@ -2,7 +2,7 @@ import PropTypes from '../_util/vue-types';
import Trigger from '../vc-trigger'; import Trigger from '../vc-trigger';
import { placements } from './placements'; import { placements } from './placements';
import Content from './Content'; import Content from './Content';
import { hasProp, getComponentFromProp, getOptionProps } from '../_util/props-util'; import { hasProp, getComponentFromProp, getOptionProps, getListeners } from '../_util/props-util';
function noop() {} function noop() {}
export default { export default {
props: { props: {
@ -69,6 +69,7 @@ export default {
if (hasProp(this, 'visible')) { if (hasProp(this, 'visible')) {
extraProps.popupVisible = this.$props.visible; extraProps.popupVisible = this.$props.visible;
} }
const listeners = getListeners(this);
const triggerProps = { const triggerProps = {
props: { props: {
popupClassName: overlayClassName, popupClassName: overlayClassName,
@ -89,9 +90,9 @@ export default {
...extraProps, ...extraProps,
}, },
on: { on: {
...this.$listeners, ...listeners,
popupVisibleChange: this.$listeners.visibleChange || noop, popupVisibleChange: listeners.visibleChange || noop,
popupAlign: this.$listeners.popupAlign || noop, popupAlign: listeners.popupAlign || noop,
}, },
ref: 'trigger', ref: 'trigger',
}; };

View File

@ -2,7 +2,13 @@ import Vue from 'vue';
import ref from 'vue-ref'; import ref from 'vue-ref';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import contains from '../_util/Dom/contains'; import contains from '../_util/Dom/contains';
import { hasProp, getComponentFromProp, getEvents, filterEmpty } from '../_util/props-util'; import {
hasProp,
getComponentFromProp,
getEvents,
filterEmpty,
getListeners,
} from '../_util/props-util';
import { requestAnimationTimeout, cancelAnimationTimeout } from '../_util/requestAnimationTimeout'; import { requestAnimationTimeout, cancelAnimationTimeout } from '../_util/requestAnimationTimeout';
import addEventListener from '../_util/Dom/addEventListener'; import addEventListener from '../_util/Dom/addEventListener';
import warning from '../_util/warning'; import warning from '../_util/warning';
@ -448,7 +454,8 @@ export default {
sPopupVisible, sPopupVisible,
}); });
} }
this.$listeners.popupVisibleChange && this.$listeners.popupVisibleChange(sPopupVisible); const listeners = getListeners(this);
listeners.popupVisibleChange && listeners.popupVisibleChange(sPopupVisible);
} }
// Always record the point position since mouseEnterDelay will delay the show // Always record the point position since mouseEnterDelay will delay the show
if (sPopupVisible && alignPoint && event) { if (sPopupVisible && alignPoint && event) {