From cb383df517dc5cd5b4d90136b533977a33611b71 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 25 Feb 2019 04:18:41 -0500
Subject: [PATCH] Fix bug to get wrapped component prop name list
---
src/hocs/with_load_more/with_load_more.js | 3 ++-
src/hocs/with_subscription/with_subscription.js | 3 ++-
src/services/component_utils/component_utils.js | 10 ++++++++++
3 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 src/services/component_utils/component_utils.js
diff --git a/src/hocs/with_load_more/with_load_more.js b/src/hocs/with_load_more/with_load_more.js
index a521014c..7d53e7ac 100644
--- a/src/hocs/with_load_more/with_load_more.js
+++ b/src/hocs/with_load_more/with_load_more.js
@@ -1,6 +1,7 @@
import Vue from 'vue'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
+import { getComponentProps } from '../../services/component_utils/component_utils'
import './with_load_more.scss'
const withLoadMore = ({
@@ -9,7 +10,7 @@ const withLoadMore = ({
childPropName = 'entries', // name of the prop to be passed into the wrapped component
additionalPropNames = [] // additional prop name list of the wrapper component
}) => (WrappedComponent) => {
- const originalProps = WrappedComponent.props || []
+ const originalProps = Object.keys(getComponentProps(WrappedComponent))
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
return Vue.component('withLoadMore', {
diff --git a/src/hocs/with_subscription/with_subscription.js b/src/hocs/with_subscription/with_subscription.js
index b6bc8358..4d3ae811 100644
--- a/src/hocs/with_subscription/with_subscription.js
+++ b/src/hocs/with_subscription/with_subscription.js
@@ -1,6 +1,7 @@
import Vue from 'vue'
import filter from 'lodash/filter'
import isEmpty from 'lodash/isEmpty'
+import { getComponentProps } from '../../services/component_utils/component_utils'
import './with_subscription.scss'
const withSubscription = ({
@@ -9,7 +10,7 @@ const withSubscription = ({
childPropName = 'content', // name of the prop to be passed into the wrapped component
additionalPropNames = [] // additional prop name list of the wrapper component
}) => (WrappedComponent) => {
- const originalProps = WrappedComponent.props || []
+ const originalProps = Object.keys(getComponentProps(WrappedComponent))
const props = filter(originalProps, v => v !== childPropName).concat(additionalPropNames)
return Vue.component('withSubscription', {
diff --git a/src/services/component_utils/component_utils.js b/src/services/component_utils/component_utils.js
new file mode 100644
index 00000000..77ea14a1
--- /dev/null
+++ b/src/services/component_utils/component_utils.js
@@ -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
+}