perf: update vc-xxx $emit to __emit

pull/2682/head
tanjinzhou 2020-07-24 14:23:14 +08:00
parent f2a0feebee
commit a50dba12aa
28 changed files with 108 additions and 98 deletions

@ -1 +1 @@
Subproject commit dd3e7a8023c35c197ff9e3fd754d6d4f8a3fc852
Subproject commit 5dfdfff5b84743a979ff315bd6d44fe9810e0dc0

View File

@ -227,7 +227,7 @@ const Calendar = {
return;
}
this.$emit('blur', event);
this.__emit('blur', event);
}, 0);
},

View File

@ -164,7 +164,7 @@ export default {
handleChange(options, setProps, e) {
if (e.type !== 'keydown' || e.keyCode === KeyCode.ENTER) {
const value = options.map(o => o[this.getFieldName('value')]);
this.$emit('update:value', value);
this.__emit('update:value', value);
this.__emit('change', value, options);
this.setPopupVisible(setProps.visible);
}

View File

@ -82,12 +82,12 @@ export default {
},
nativeEvent: e,
};
this.$emit('update:checked', eventObj);
this.$emit('change', eventObj);
this.__emit('update:checked', eventObj);
this.__emit('change', eventObj);
this.eventShiftKey = false;
},
onClick(e) {
this.$emit('click', e);
this.__emit('click', e);
// onChangeshiftKey使onClick hack
this.eventShiftKey = e.shiftKey;
},

View File

@ -118,8 +118,8 @@ export default {
},
setActiveKey(activeKey) {
this.setState({ stateActiveKey: activeKey });
this.$emit('change', this.accordion ? activeKey[0] : activeKey);
this.$emit('update:activeKey', this.accordion ? activeKey[0] : activeKey);
this.__emit('change', this.accordion ? activeKey[0] : activeKey);
this.__emit('update:activeKey', this.accordion ? activeKey[0] : activeKey);
},
},
render() {

View File

@ -2,9 +2,11 @@ import PanelContent from './PanelContent';
import { initDefaultProps, getComponent, getSlot } from '../../_util/props-util';
import { panelProps } from './commonProps';
import { Transition } from 'vue';
import BaseMixin from '../../_util/BaseMixin';
export default {
name: 'Panel',
mixins: [BaseMixin],
props: initDefaultProps(panelProps(), {
showArrow: true,
isActive: false,
@ -14,7 +16,7 @@ export default {
}),
methods: {
handleItemClick() {
this.$emit('itemClick', this.panelKey);
this.__emit('itemClick', this.panelKey);
},
handleKeyPress(e) {
if (e.key === 'Enter' || e.keyCode === 13 || e.which === 13) {

View File

@ -146,15 +146,15 @@ const Drawer = {
onKeyDown(e) {
if (e.keyCode === KeyCode.ESC) {
e.stopPropagation();
this.$emit('close', e);
this.__emit('close', e);
}
},
onMaskTouchEnd(e) {
this.$emit('close', e);
this.__emit('close', e);
this.onTouchEnd(e, true);
},
onIconTouchEnd(e) {
this.$emit('handleClick', e);
this.__emit('handleClick', e);
this.onTouchEnd(e);
},
onTouchEnd(e, close) {

View File

@ -62,7 +62,7 @@ export default {
sVisible: false,
});
}
this.$emit('overlayClick', e);
this.__emit('overlayClick', e);
if (overlayProps.onClick) {
overlayProps.onClick(e);
}
@ -74,7 +74,7 @@ export default {
sVisible: visible,
});
}
this.$emit('update:visible', visible);
this.__emit('update:visible', visible);
this.__emit('visibleChange', visible);
},

View File

@ -160,8 +160,8 @@ export default {
typeof nextValue === 'number' &&
nextValue > max
) {
this.$emit('update:value', max);
this.$emit('change', max);
this.__emit('update:value', max);
this.__emit('change', max);
}
if (
'min' in props &&
@ -169,8 +169,8 @@ export default {
typeof nextValue === 'number' &&
nextValue < min
) {
this.$emit('update:value', min);
this.$emit('change', min);
this.__emit('update:value', min);
this.__emit('change', min);
}
}
this.prevProps = { ...props };
@ -254,19 +254,19 @@ export default {
this.down(e, ratio);
this.stop();
} else if (e.keyCode === KeyCode.ENTER) {
this.$emit('pressEnter', e);
this.__emit('pressEnter', e);
}
// Trigger user key down
this.recordCursorPosition();
this.lastKeyCode = e.keyCode;
this.$emit('keydown', e, ...args);
this.__emit('keydown', e, ...args);
},
onKeyUp(e, ...args) {
this.stop();
this.recordCursorPosition();
this.$emit('keyup', e, ...args);
this.__emit('keyup', e, ...args);
},
onChange(e) {
if (this.focused) {
@ -275,14 +275,14 @@ export default {
this.rawInput = this.parser(this.getValueFromEvent(e));
this.setState({ inputValue: this.rawInput });
const num = this.toNumber(this.rawInput); // valid number or invalid string
this.$emit('update:value', num);
this.$emit('change', num);
this.__emit('update:value', num);
this.__emit('change', num);
},
onFocus(...args) {
this.setState({
focused: true,
});
this.$emit('focus', ...args);
this.__emit('focus', ...args);
},
onBlur(...args) {
this.inputting = false;
@ -295,7 +295,7 @@ export default {
const originValue = this.inputRef.value;
const inputValue = this.getInputDisplayValue({ focused: false, sValue: newValue });
this.inputRef.value = inputValue;
this.$emit('blur', ...args);
this.__emit('blur', ...args);
this.inputRef.value = originValue;
}
},
@ -372,8 +372,8 @@ export default {
);
}
if (changed) {
this.$emit('update:value', newValue);
this.$emit('change', newValue);
this.__emit('update:value', newValue);
this.__emit('change', newValue);
}
return newValue;
},
@ -621,7 +621,7 @@ export default {
this.stepFn('up', e, ratio, recursive);
},
handleInputClick() {
this.$emit('click');
this.__emit('click');
},
saveUp(node) {
this.upHandlerRef = node;

View File

@ -60,7 +60,7 @@ const Mentions = {
} else {
this.$forceUpdate();
}
this.$emit('change', value);
this.__emit('change', value);
},
onChange({ target: { value, composing }, isComposing }) {
if (isComposing || composing) return;
@ -143,7 +143,7 @@ const Mentions = {
* If met `space` means user finished searching.
*/
if (validateMeasure) {
this.$emit('search', measureText, measurePrefix);
this.__emit('search', measureText, measurePrefix);
}
} else if (measuring) {
this.stopMeasure();
@ -165,7 +165,7 @@ const Mentions = {
window.clearTimeout(this.focusId);
const { isFocus } = this.$data;
if (!isFocus && event) {
this.$emit('focus', event);
this.__emit('focus', event);
}
this.setState({ isFocus: true });
},
@ -173,7 +173,7 @@ const Mentions = {
this.focusId = window.setTimeout(() => {
this.setState({ isFocus: false });
this.stopMeasure();
this.$emit('blur', event);
this.__emit('blur', event);
}, 100);
},
selectOption(option) {
@ -193,7 +193,7 @@ const Mentions = {
setInputSelection(this.$refs.textarea, selectionLocation);
});
this.$emit('select', option, measurePrefix);
this.__emit('select', option, measurePrefix);
},
setActiveIndex(activeIndex) {
this.setState({

View File

@ -1,8 +1,10 @@
import PropTypes from '../_util/vue-types';
import classNames from 'classnames';
import BaseMixin from '../_util/BaseMixin';
export default {
name: 'Pager',
mixins: [BaseMixin],
inheritAttrs: false,
props: {
rootPrefixCls: PropTypes.string,
@ -18,10 +20,10 @@ export default {
},
methods: {
handleClick() {
this.$emit('click', this.page);
this.__emit('click', this.page);
},
handleKeyPress(event) {
this.$emit('keypress', event, this.handleClick, this.page);
this.__emit('keypress', event, this.handleClick, this.page);
},
},
render() {

View File

@ -234,10 +234,10 @@ export default {
});
}
}
this.$emit('update:pageSize', size);
this.$emit('showSizeChange', current, size);
this.__emit('update:pageSize', size);
this.__emit('showSizeChange', current, size);
if (current !== preCurrent) {
this.$emit('update:current', current);
this.__emit('update:current', current);
}
},
handleChange(p) {
@ -256,9 +256,9 @@ export default {
stateCurrentInputValue: page,
});
}
// this.$emit('input', page)
this.$emit('update:current', page);
this.$emit('change', page, this.statePageSize);
// this.__emit('input', page)
this.__emit('update:current', page);
this.__emit('change', page, this.statePageSize);
return page;
}
return this.stateCurrent;

View File

@ -71,14 +71,14 @@ export default {
cleanedValue: null,
});
}
this.$emit('hoverChange', hoverValue);
this.__emit('hoverChange', hoverValue);
},
onMouseLeave() {
this.setState({
hoverValue: undefined,
cleanedValue: null,
});
this.$emit('hoverChange', undefined);
this.__emit('hoverChange', undefined);
},
onClick(event, index) {
const { allowClear, sValue: value } = this;
@ -97,13 +97,13 @@ export default {
this.setState({
focused: true,
});
this.$emit('focus');
this.__emit('focus');
},
onBlur() {
this.setState({
focused: false,
});
this.$emit('blur');
this.__emit('blur');
},
onKeyDown(event) {
const { keyCode } = event;
@ -126,7 +126,7 @@ export default {
this.changeValue(sValue);
event.preventDefault();
}
this.$emit('keydown', event);
this.__emit('keydown', event);
},
getStarDOM(index) {
return this.$refs['stars' + index].$el;
@ -159,8 +159,8 @@ export default {
sValue: value,
});
}
this.$emit('update:value', value);
this.$emit('change', value);
this.__emit('update:value', value);
this.__emit('change', value);
},
},
render() {

View File

@ -21,11 +21,11 @@ export default {
methods: {
onHover(e) {
const { index } = this;
this.$emit('hover', e, index);
this.__emit('hover', e, index);
},
onClick(e) {
const { index } = this;
this.$emit('click', e, index);
this.__emit('click', e, index);
},
onKeyDown(e) {
const { index } = this.$props;

View File

@ -1,9 +1,11 @@
// based on rc-resize-observer 0.1.3
import ResizeObserver from 'resize-observer-polyfill';
import BaseMixin from '../_util/BaseMixin';
// Still need to be compatible with React 15, we use class component here
const VueResizeObserver = {
name: 'ResizeObserver',
mixins: [BaseMixin],
props: {
disabled: Boolean,
onResize: Function,
@ -66,7 +68,7 @@ const VueResizeObserver = {
const size = { width: fixedWidth, height: fixedHeight };
this.width = fixedWidth;
this.height = fixedHeight;
this.$emit('resize', size);
this.__emit('resize', size);
}
},

View File

@ -733,7 +733,7 @@ const Select = {
return;
}
this.setOpenState(false);
this.$emit('blur', this.getVLForOnChange(value));
this.__emit('blur', this.getVLForOnChange(value));
}, 200);
},
inputFocus(e) {
@ -868,7 +868,7 @@ const Select = {
this.forcePopupAlign,
);
if (fireSearch) {
this.$emit('search', inputValue);
this.__emit('search', inputValue);
}
}
},
@ -981,7 +981,7 @@ const Select = {
this.focusTimer = window.setTimeout(() => {
// this._focused = true
// this.updateFocusClassName()
this.$emit('focus');
this.__emit('focus');
}, 10);
},
@ -1055,7 +1055,7 @@ const Select = {
label: this.getLabelBySingleValue(selectedKey),
};
}
this.$emit('deselect', event, this.getOptionBySingleValue(selectedKey));
this.__emit('deselect', event, this.getOptionBySingleValue(selectedKey));
}
this.fireChange(value);
},
@ -1067,7 +1067,7 @@ const Select = {
}
},
fireSelect(value) {
this.$emit('select', this.getVLBySingleValue(value), this.getOptionBySingleValue(value));
this.__emit('select', this.getVLBySingleValue(value), this.getOptionBySingleValue(value));
},
fireChange(value) {
if (!hasProp(this, 'value')) {
@ -1081,8 +1081,8 @@ const Select = {
const vls = this.getVLForOnChange(value);
const options = this.getOptionsBySingleValue(value);
this._valueOptions = options;
this.$emit('update:value', vls);
this.$emit('change', vls, isMultipleOrTags(this.$props) ? options : options[0]);
this.__emit('update:value', vls);
this.__emit('change', vls, isMultipleOrTags(this.$props) ? options : options[0]);
},
isChildDisabled(key) {
@ -1500,7 +1500,7 @@ const Select = {
// }
// this._focused = true;
// this.updateFocusClassName();
// this.$emit('focus');
// this.__emit('focus');
},
selectionRefBlur(e) {
if (isMultipleOrTagsOrCombobox(this.$props)) {

View File

@ -186,7 +186,7 @@ export default {
image.onload = handler;
image.onerror = () => {
handler();
this.$emit('lazyLoadError');
this.__emit('lazyLoadError');
};
}
}
@ -211,7 +211,7 @@ export default {
this.setState(state => ({
lazyLoadedList: state.lazyLoadedList.concat(slidesToLoad),
}));
this.$emit('lazyLoad', slidesToLoad);
this.__emit('lazyLoad', slidesToLoad);
} else {
if (this.lazyLoadTimer) {
clearInterval(this.lazyLoadTimer);
@ -234,7 +234,7 @@ export default {
value => this.lazyLoadedList.indexOf(value) < 0,
);
if (this.$attrs.onLazyLoad && slidesToLoad.length > 0) {
this.$emit('lazyLoad', slidesToLoad);
this.__emit('lazyLoad', slidesToLoad);
}
this.setState(state, () => {
asNavFor &&
@ -433,7 +433,7 @@ export default {
},
beforeMount() {
this.ssrInit();
this.$emit('init');
this.__emit('init');
if (this.lazyLoad) {
const slidesToLoad = getOnDemandLazySlides({
...this.$props,
@ -443,7 +443,7 @@ export default {
this.setState(prevState => ({
lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad),
}));
this.$emit('lazyLoad', slidesToLoad);
this.__emit('lazyLoad', slidesToLoad);
}
}
},
@ -508,7 +508,7 @@ export default {
},
updated() {
this.checkImagesLoad();
this.$emit('reInit');
this.__emit('reInit');
if (this.lazyLoad) {
const slidesToLoad = getOnDemandLazySlides({
...this.$props,
@ -518,7 +518,7 @@ export default {
this.setState(prevState => ({
lazyLoadedList: prevState.lazyLoadedList.concat(slidesToLoad),
}));
this.$emit('lazyLoad');
this.__emit('lazyLoad');
}
}
// if (this.props.onLazyLoad) {

View File

@ -106,7 +106,7 @@ const Range = {
const newValues = value.map(v => {
return utils.ensureValueInRange(v, this.$props);
});
this.$emit('change', newValues);
this.__emit('change', newValues);
}
},
onChange(state) {
@ -129,11 +129,11 @@ const Range = {
const data = { ...this.$data, ...state };
const changedValue = data.bounds;
this.$emit('change', changedValue);
this.__emit('change', changedValue);
},
onStart(position) {
const { bounds } = this;
this.$emit('beforeChange', bounds);
this.__emit('beforeChange', bounds);
const value = this.calcValueByPos(position);
this.startValue = value;
@ -157,7 +157,7 @@ const Range = {
const { sHandle } = this;
this.removeDocumentEvents();
if (sHandle !== null || force) {
this.$emit('afterChange', this.bounds);
this.__emit('afterChange', this.bounds);
}
this.setState({ sHandle: null });
},
@ -267,7 +267,7 @@ const Range = {
// so trigger focus will invoke handler's onEnd and another handler's onStart too early,
// cause onBeforeChange and onAfterChange receive wrong value.
// here use setState callback to hackbut not elegant
this.$emit('afterChange', nextBounds);
this.__emit('afterChange', nextBounds);
this.setState({}, () => {
this.handlesRefs[nextHandle].focus();
});

View File

@ -51,7 +51,7 @@ const Slider = {
this.setState({ sValue: nextValue });
if (utils.isValueOutOfRange(newValue, this.$props)) {
this.$emit('change', nextValue);
this.__emit('change', nextValue);
}
},
onChange(state) {
@ -62,12 +62,12 @@ const Slider = {
}
const changedValue = nextState.sValue;
this.$emit('change', changedValue);
this.__emit('change', changedValue);
},
onStart(position) {
this.setState({ dragging: true });
const { sValue } = this;
this.$emit('beforeChange', sValue);
this.__emit('beforeChange', sValue);
const value = this.calcValueByPos(position);
@ -82,7 +82,7 @@ const Slider = {
const { dragging } = this;
this.removeDocumentEvents();
if (dragging || force) {
this.$emit('afterChange', this.sValue);
this.__emit('afterChange', this.sValue);
}
this.setState({ dragging: false });
},
@ -105,7 +105,7 @@ const Slider = {
if (value === sValue) return;
this.onChange({ sValue: value });
this.$emit('afterChange', value);
this.__emit('afterChange', value);
this.onEnd();
}
},

View File

@ -7,6 +7,7 @@ import Steps from './Steps';
import Marks from './Marks';
import Handle from '../Handle';
import * as utils from '../utils';
import BaseMixin from '../../../_util/BaseMixin';
function noop() {}
@ -36,7 +37,7 @@ export default function createSlider(Component) {
return {
name: 'createSlider',
inheritAttrs: false,
mixins: [Component],
mixins: [BaseMixin, Component],
// model: {
// prop: 'value',
// event: 'change',
@ -143,12 +144,12 @@ export default function createSlider(Component) {
this.dragOffset = 0;
this.onStart(handlePosition);
utils.pauseEvent(e);
this.$emit('focus', e);
this.__emit('focus', e);
}
},
onBlur(e) {
this.onEnd();
this.$emit('blur', e);
this.__emit('blur', e);
},
onMouseUp() {
if (this.handlesRefs[this.prevMovedHandleIndex]) {

View File

@ -1,5 +1,6 @@
import PropTypes from '../_util/vue-types';
import { getOptionProps, getComponent } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
function isString(str) {
return typeof str === 'string';
@ -7,6 +8,7 @@ function isString(str) {
function noop() {}
export default {
name: 'Step',
mixins: [BaseMixin],
props: {
prefixCls: PropTypes.string,
wrapperStyle: PropTypes.object,
@ -33,8 +35,8 @@ export default {
},
methods: {
onItemClick(...args) {
this.$emit('click', ...args);
this.$emit('stepClick', this.stepIndex);
this.__emit('click', ...args);
this.__emit('stepClick', this.stepIndex);
},
renderIconNode() {
const { prefixCls, stepNumber, status, iconPrefix, icons, progressDot } = getOptionProps(

View File

@ -58,8 +58,8 @@ export default {
onStepClick(next) {
const { current } = this.$props;
if (current !== next) {
this.$emit('change', next);
this.$emit('update:current', next);
this.__emit('change', next);
this.__emit('update:current', next);
}
},
calcStepOffsetWidth() {

View File

@ -49,13 +49,13 @@ export default {
if (!hasProp(this, 'checked')) {
this.stateChecked = checked;
}
this.$emit('change', checked, e);
this.$emit('update:checked', checked);
this.__emit('change', checked, e);
this.__emit('update:checked', checked);
},
handleClick(e) {
const checked = !this.stateChecked;
this.setChecked(checked, e);
this.$emit('click', checked, e);
this.__emit('click', checked, e);
},
handleKeyDown(e) {
if (e.keyCode === 37) {
@ -69,7 +69,7 @@ export default {
handleMouseUp(e) {
this.refSwitchNode?.blur();
this.$emit('mouseup', e);
this.__emit('mouseup', e);
},
focus() {
this.refSwitchNode?.focus();

View File

@ -140,7 +140,7 @@ export default {
_activeKey: activeKey,
});
}
this.$emit('update:activeKey', activeKey);
this.__emit('update:activeKey', activeKey);
this.__emit('change', activeKey);
}
},

View File

@ -481,7 +481,7 @@ const Tree = {
_halfCheckedKeys: halfCheckedKeys,
});
}
this.$emit('update:checkedKeys', checkedObj);
this.__emit('update:checkedKeys', checkedObj);
this.__emit('check', checkedObj, eventObj);
},

View File

@ -89,7 +89,7 @@ const AjaxUploader = {
this.uploadFiles(successFiles);
if (errorFiles.length) {
this.$emit('reject', errorFiles);
this.__emit('reject', errorFiles);
}
}
},
@ -161,19 +161,19 @@ const AjaxUploader = {
withCredentials: this.withCredentials,
method: props.method || 'post',
onProgress: e => {
this.$emit('progress', e, file);
this.__emit('progress', e, file);
},
onSuccess: (ret, xhr) => {
delete this.reqs[uid];
this.$emit('success', ret, file, xhr);
this.__emit('success', ret, file, xhr);
},
onError: (err, ret) => {
delete this.reqs[uid];
this.$emit('error', err, ret, file);
this.__emit('error', err, ret, file);
},
};
this.reqs[uid] = request(requestOption);
this.$emit('start', file);
this.__emit('start', file);
});
});
},

View File

@ -16,6 +16,7 @@ const IFRAME_STYLE = {
// diferent from AjaxUpload, can only upload on at one time, serial seriously
const IframeUploader = {
name: 'IframeUploader',
mixins: [BaseMixin],
props: {
componentTag: PropTypes.string,
@ -51,14 +52,14 @@ const IframeUploader = {
doc.body.removeChild(script);
}
response = doc.body.innerHTML;
this.$emit('success', response, file);
this.__emit('success', response, file);
} catch (err) {
warning(
false,
'cross domain error for Upload. Maybe server should return document.domain script. see Note from https://github.com/react-component/upload',
);
response = 'cross-domain';
this.$emit('error', err, null, file);
this.__emit('error', err, null, file);
}
this.endUpload();
},
@ -239,7 +240,7 @@ const IframeUploader = {
formNode.setAttribute('action', action);
formNode.submit();
dataSpan.innerHTML = '';
this.$emit('start', file);
this.__emit('start', file);
});
},
},

View File

@ -63,7 +63,7 @@ export default {
this.Component = this.getComponent();
this.$forceUpdate();
nextTick(() => {
this.$emit('ready');
this.__emit('ready');
});
}
});