UNPKG

ant-design-vue

Version:

An enterprise-class UI design language and Vue-based implementation

55 lines (51 loc) 1.81 kB
import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props'; import _extends from 'babel-runtime/helpers/extends'; import PropTypes from './vue-types'; import { getOptionProps } from './props-util'; function getDisplayName(WrappedComponent) { return WrappedComponent.name || 'Component'; } export default function wrapWithConnect(WrappedComponent) { var tempProps = WrappedComponent.props || {}; var methods = WrappedComponent.methods || {}; var props = {}; Object.keys(tempProps).forEach(function (k) { props[k] = PropTypes.any; }); WrappedComponent.props.__propsSymbol__ = PropTypes.any; WrappedComponent.props.children = PropTypes.array.def([]); var ProxyWrappedComponent = { props: props, model: WrappedComponent.model, name: 'Proxy_' + getDisplayName(WrappedComponent), methods: { getProxyWrappedInstance: function getProxyWrappedInstance() { return this.$refs.wrappedInstance; } }, render: function render() { var h = arguments[0]; var $listeners = this.$listeners, _$slots = this.$slots, $slots = _$slots === undefined ? {} : _$slots, $attrs = this.$attrs; var props = getOptionProps(this); var wrapProps = { props: _extends({}, props, { __propsSymbol__: Symbol(), children: $slots['default'] || [] }), on: $listeners, attrs: $attrs }; return h(WrappedComponent, _mergeJSXProps([wrapProps, { ref: 'wrappedInstance' }])); } }; Object.keys(methods).map(function (m) { ProxyWrappedComponent.methods[m] = function () { var _getProxyWrappedInsta; (_getProxyWrappedInsta = this.getProxyWrappedInstance())[m].apply(_getProxyWrappedInsta, arguments); }; }); return ProxyWrappedComponent; }