chore: update some util

pull/2324/head
tangjinzhou 2020-05-27 23:56:00 +08:00
parent adee8604b2
commit cfe61108c5
2 changed files with 24 additions and 28 deletions

@ -1 +1 @@
Subproject commit cbf75b264e8f00f820a73fd2204183d17ca8648b Subproject commit adbfcd30aeb6c125defa35102ed659f1be03c672

View File

@ -1,9 +1,9 @@
import isPlainObject from 'lodash/isPlainObject'; import isPlainObject from 'lodash/isPlainObject';
import classNames from 'classnames'; import classNames from 'classnames';
function getType(fn) { // function getType(fn) {
const match = fn && fn.toString().match(/^\s*function (\w+)/); // const match = fn && fn.toString().match(/^\s*function (\w+)/);
return match ? match[1] : ''; // return match ? match[1] : '';
} // }
const camelizeRE = /-(\w)/g; const camelizeRE = /-(\w)/g;
const camelize = str => { const camelize = str => {
@ -35,10 +35,10 @@ const slotHasProp = (slot, prop) => {
const propsData = $options.propsData || {}; const propsData = $options.propsData || {};
return prop in propsData; return prop in propsData;
}; };
const filterProps = (props, propsData = {}) => { const filterProps = props => {
const res = {}; const res = {};
Object.keys(props).forEach(k => { Object.keys(props).forEach(k => {
if (k in propsData || props[k] !== undefined) { if (props[k] !== undefined) {
res[k] = props[k]; res[k] = props[k];
} }
}); });
@ -66,11 +66,7 @@ const getSlots = ele => {
return { ...slots, ...getScopedSlots(ele) }; return { ...slots, ...getScopedSlots(ele) };
}; };
const getSlot = (self, name = 'default', options = {}) => { const getSlot = (self, name = 'default', options = {}) => {
return ( return self.$slots[name] && self.$slots[name](options);
(self.$scopedSlots && self.$scopedSlots[name] && self.$scopedSlots[name](options)) ||
self.$slots[name] ||
undefined
);
}; };
const getAllChildren = ele => { const getAllChildren = ele => {
@ -92,22 +88,22 @@ const getSlotOptions = ele => {
return componentOptions ? componentOptions.Ctor.options || {} : {}; return componentOptions ? componentOptions.Ctor.options || {} : {};
}; };
const getOptionProps = instance => { const getOptionProps = instance => {
if (instance.componentOptions) { // if (instance.componentOptions) {
const componentOptions = instance.componentOptions; // const componentOptions = instance.componentOptions;
const { propsData = {}, Ctor = {} } = componentOptions; // const { propsData = {}, Ctor = {} } = componentOptions;
const props = (Ctor.options || {}).props || {}; // const props = (Ctor.options || {}).props || {};
const res = {}; // const res = {};
for (const [k, v] of Object.entries(props)) { // for (const [k, v] of Object.entries(props)) {
const def = v.default; // const def = v.default;
if (def !== undefined) { // if (def !== undefined) {
res[k] = // res[k] =
typeof def === 'function' && getType(v.type) !== 'Function' ? def.call(instance) : def; // typeof def === 'function' && getType(v.type) !== 'Function' ? def.call(instance) : def;
} // }
} // }
return { ...res, ...propsData }; // return { ...res, ...propsData };
} // }
const { $options = {}, $props = {} } = instance; const { $props = {} } = instance;
return filterProps($props, $options.propsData); return filterProps($props);
}; };
const getComponentFromProp = (instance, prop, options = instance, execute = true) => { const getComponentFromProp = (instance, prop, options = instance, execute = true) => {