Fix bug to get wrapped component prop name list
This commit is contained in:
parent
5c43374588
commit
cb383df517
3 changed files with 14 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import filter from 'lodash/filter'
|
import filter from 'lodash/filter'
|
||||||
import isEmpty from 'lodash/isEmpty'
|
import isEmpty from 'lodash/isEmpty'
|
||||||
|
import { getComponentProps } from '../../services/component_utils/component_utils'
|
||||||
import './with_load_more.scss'
|
import './with_load_more.scss'
|
||||||
|
|
||||||
const withLoadMore = ({
|
const withLoadMore = ({
|
||||||
|
@ -9,7 +10,7 @@ const withLoadMore = ({
|
||||||
childPropName = 'entries', // name of the prop to be passed into the wrapped component
|
childPropName = 'entries', // name of the prop to be passed into the wrapped component
|
||||||
additionalPropNames = [] // additional prop name list of the wrapper component
|
additionalPropNames = [] // additional prop name list of the wrapper component
|
||||||
}) => (WrappedComponent) => {
|
}) => (WrappedComponent) => {
|
||||||
const originalProps = WrappedComponent.props || []
|
const originalProps = Object.keys(getComponentProps(WrappedComponent))
|
||||||
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
|
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
|
||||||
|
|
||||||
return Vue.component('withLoadMore', {
|
return Vue.component('withLoadMore', {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import filter from 'lodash/filter'
|
import filter from 'lodash/filter'
|
||||||
import isEmpty from 'lodash/isEmpty'
|
import isEmpty from 'lodash/isEmpty'
|
||||||
|
import { getComponentProps } from '../../services/component_utils/component_utils'
|
||||||
import './with_subscription.scss'
|
import './with_subscription.scss'
|
||||||
|
|
||||||
const withSubscription = ({
|
const withSubscription = ({
|
||||||
|
@ -9,7 +10,7 @@ const withSubscription = ({
|
||||||
childPropName = 'content', // name of the prop to be passed into the wrapped component
|
childPropName = 'content', // name of the prop to be passed into the wrapped component
|
||||||
additionalPropNames = [] // additional prop name list of the wrapper component
|
additionalPropNames = [] // additional prop name list of the wrapper component
|
||||||
}) => (WrappedComponent) => {
|
}) => (WrappedComponent) => {
|
||||||
const originalProps = WrappedComponent.props || []
|
const originalProps = Object.keys(getComponentProps(WrappedComponent))
|
||||||
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
|
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
|
||||||
|
|
||||||
return Vue.component('withSubscription', {
|
return Vue.component('withSubscription', {
|
||||||
|
|
10
src/services/component_utils/component_utils.js
Normal file
10
src/services/component_utils/component_utils.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import isFunction from 'lodash/isFunction'
|
||||||
|
|
||||||
|
const getComponentOptions = (Component) => (isFunction(Component)) ? Component.options : Component
|
||||||
|
|
||||||
|
const getComponentProps = (Component) => getComponentOptions(Component).props
|
||||||
|
|
||||||
|
export {
|
||||||
|
getComponentOptions,
|
||||||
|
getComponentProps
|
||||||
|
}
|
Loading…
Reference in a new issue