perf: menu

pull/2468/head
tangjinzhou 2020-06-18 23:50:02 +08:00
parent 82bb43bbe8
commit 0910df5a95
7 changed files with 21 additions and 27 deletions

View File

@ -1,9 +1,8 @@
import shallowEqual from 'shallowequal'; import shallowEqual from 'shallowequal';
import { inject, createVNode } from 'vue'; import { inject, createVNode, watchEffect } from 'vue';
import omit from 'omit.js'; import omit from 'omit.js';
import { getOptionProps } from '../props-util'; import { getOptionProps } from '../props-util';
import PropTypes from '../vue-types'; import PropTypes from '../vue-types';
import proxyComponent from '../proxyComponent';
function getDisplayName(WrappedComponent) { function getDisplayName(WrappedComponent) {
return WrappedComponent.name || 'Component'; return WrappedComponent.name || 'Component';
@ -33,16 +32,14 @@ export default function connect(mapStateToProps) {
data() { data() {
this.store = this.storeContext.store; this.store = this.storeContext.store;
this.preProps = omit(getOptionProps(this), ['__propsSymbol__']); this.preProps = omit(getOptionProps(this), ['__propsSymbol__']);
return { watchEffect(() => {
subscribed: finnalMapStateToProps(this.store.getState(), this.$props),
};
},
watch: {
__propsSymbol__() {
if (mapStateToProps && mapStateToProps.length === 2) { if (mapStateToProps && mapStateToProps.length === 2) {
this.subscribed = finnalMapStateToProps(this.store.getState(), this.$props); this.subscribed = finnalMapStateToProps(this.store.getState(), this.$props);
} }
}, });
return {
subscribed: finnalMapStateToProps(this.store.getState(), this.$props),
};
}, },
mounted() { mounted() {
this.trySubscribe(); this.trySubscribe();
@ -56,7 +53,7 @@ export default function connect(mapStateToProps) {
if (!this.unsubscribe) { if (!this.unsubscribe) {
return; return;
} }
const props = omit(getOptionProps(this), ['__propsSymbol__']); const props = getOptionProps(this);
const nextSubscribed = finnalMapStateToProps(this.store.getState(), props); const nextSubscribed = finnalMapStateToProps(this.store.getState(), props);
if ( if (
!shallowEqual(this.preProps, props) || !shallowEqual(this.preProps, props) ||
@ -86,7 +83,7 @@ export default function connect(mapStateToProps) {
render() { render() {
const { $slots = {}, subscribed, store, $attrs } = this; const { $slots = {}, subscribed, store, $attrs } = this;
const props = getOptionProps(this); const props = getOptionProps(this);
this.preProps = { ...omit(props, ['__propsSymbol__']) }; this.preProps = { ...props };
const wrapProps = { const wrapProps = {
...props, ...props,
...subscribed, ...subscribed,
@ -95,9 +92,8 @@ export default function connect(mapStateToProps) {
ref: 'wrappedInstance', ref: 'wrappedInstance',
}; };
return createVNode(WrappedComponent, wrapProps, $slots); return createVNode(WrappedComponent, wrapProps, $slots);
// return <WrappedComponent {...wrapProps} ref="wrappedInstance"></WrappedComponent>;
}, },
}; };
return proxyComponent(Connect); return Connect;
}; };
} }

View File

@ -45,14 +45,13 @@ export default {
...tooltipProps, ...tooltipProps,
placement: 'right', placement: 'right',
overlayClassName: `${rootPrefixCls}-inline-collapsed-tooltip`, overlayClassName: `${rootPrefixCls}-inline-collapsed-tooltip`,
}; children: (
// return <div>ddd</div>;
return (
<Tooltip {...toolTipProps}>
<Item {...itemProps} ref="menuItem"> <Item {...itemProps} ref="menuItem">
{getSlot(this)} {getSlot(this)}
</Item> </Item>
</Tooltip> ),
); };
// return <div>ddd</div>;
return <Tooltip {...toolTipProps}></Tooltip>;
}, },
}; };

View File

@ -173,7 +173,7 @@ export default {
const { getPopupContainer: getContextPopupContainer } = this.configProvider; const { getPopupContainer: getContextPopupContainer } = this.configProvider;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('tooltip', customizePrefixCls); const prefixCls = getPrefixCls('tooltip', customizePrefixCls);
let children = filterEmpty(getSlot(this)); let children = this.children || filterEmpty(getSlot(this));
children = children.length === 1 ? children[0] : children; children = children.length === 1 ? children[0] : children;
let sVisible = $data.sVisible; let sVisible = $data.sVisible;
// Hide tooltip when there is no title // Hide tooltip when there is no title

View File

@ -31,4 +31,5 @@ export default () => ({
destroyTooltipOnHide: PropTypes.bool.def(false), destroyTooltipOnHide: PropTypes.bool.def(false),
align: PropTypes.object.def(() => ({})), align: PropTypes.object.def(() => ({})),
builtinPlacements: PropTypes.object, builtinPlacements: PropTypes.object,
children: PropTypes.any,
}); });

View File

@ -136,10 +136,10 @@ const MenuItem = {
}, },
render() { render() {
const props = { ...this.$props, ...this.$attrs }; const { class: cls, style, ...props } = { ...this.$props, ...this.$attrs };
const className = { const className = {
[props.class]: props.class, [cls]: !!cls,
[this.getPrefixCls()]: true, [this.getPrefixCls()]: true,
[this.getActiveClassName()]: !props.disabled && props.active, [this.getActiveClassName()]: !props.disabled && props.active,
[this.getSelectedClassName()]: props.isSelected, [this.getSelectedClassName()]: props.isSelected,
@ -173,9 +173,9 @@ const MenuItem = {
onMouseenter: props.disabled ? noop : this.onMouseEnter, onMouseenter: props.disabled ? noop : this.onMouseEnter,
}; };
const style = { ...(props.style || {}) }; const styles = { ...(style || {}) };
if (props.mode === 'inline') { if (props.mode === 'inline') {
style.paddingLeft = `${props.inlineIndent * props.level}px`; styles.paddingLeft = `${props.inlineIndent * props.level}px`;
} }
menuAllProps.forEach(key => delete props[key]); menuAllProps.forEach(key => delete props[key]);
const liProps = { const liProps = {
@ -186,7 +186,7 @@ const MenuItem = {
}; };
delete liProps.children; delete liProps.children;
return ( return (
<li {...liProps} style={style} class={className}> <li {...liProps} style={styles} class={className}>
{getSlot(this)} {getSlot(this)}
{getComponent(this, 'itemIcon', props)} {getComponent(this, 'itemIcon', props)}
</li> </li>

View File

@ -116,7 +116,6 @@ const SubPopupMenu = {
expandIcon: PropTypes.any, expandIcon: PropTypes.any,
overflowedIndicator: PropTypes.any, overflowedIndicator: PropTypes.any,
children: PropTypes.any.def([]), children: PropTypes.any.def([]),
__propsSymbol__: PropTypes.any, // mock componentWillReceiveProps
}, },
{ {
prefixCls: 'rc-menu', prefixCls: 'rc-menu',

View File

@ -111,7 +111,6 @@ export const menuAllProps = [
'onTitleMouseenter', 'onTitleMouseenter',
'onTitleMouseleave', 'onTitleMouseleave',
'onTitleClick', 'onTitleClick',
'__propsSymbol__',
'slots', 'slots',
'ref', 'ref',
'isRootMenu', 'isRootMenu',