aboutsummaryrefslogtreecommitdiff
path: root/src/hocs
diff options
context:
space:
mode:
authortaehoon <th.dev91@gmail.com>2019-02-13 14:30:12 -0500
committertaehoon <th.dev91@gmail.com>2019-02-20 13:30:30 -0500
commit94e6de11b7f9aebbc0130c836f334921fc70ae81 (patch)
tree0aae54395e64f04ed96125bedf5095cf426f9dea /src/hocs
parenta817cc7cb464d804ccd8af2bbe22e9b738959a3a (diff)
Add withList hoc and remove UserList component
Diffstat (limited to 'src/hocs')
-rw-r--r--src/hocs/with_list/with_list.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/hocs/with_list/with_list.js b/src/hocs/with_list/with_list.js
new file mode 100644
index 00000000..21aa288b
--- /dev/null
+++ b/src/hocs/with_list/with_list.js
@@ -0,0 +1,27 @@
+import Vue from 'vue'
+import map from 'lodash/map'
+
+const defaultEntryPropsGetter = entry => ({ entry })
+const defaultKeyGetter = entry => entry.id
+
+const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter) => {
+ return Vue.component('withList', {
+ render (createElement) {
+ return (
+ <div class="with-list">
+ {map(this.entries, (entry, index) => {
+ const props = {
+ key: getKey(entry, index),
+ ...this.$props.entryProps,
+ ...getEntryProps(entry, index)
+ }
+ return <Component {...{ attrs: props }} />
+ })}
+ </div>
+ )
+ },
+ props: ['entries', 'entryProps']
+ })
+}
+
+export default withList