From 94e6de11b7f9aebbc0130c836f334921fc70ae81 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Wed, 13 Feb 2019 14:30:12 -0500
Subject: Add withList hoc and remove UserList component
---
src/hocs/with_list/with_list.js | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 src/hocs/with_list/with_list.js
(limited to 'src/hocs/with_list/with_list.js')
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 (
+
+ {map(this.entries, (entry, index) => {
+ const props = {
+ key: getKey(entry, index),
+ ...this.$props.entryProps,
+ ...getEntryProps(entry, index)
+ }
+ return
+ })}
+
+ )
+ },
+ props: ['entries', 'entryProps']
+ })
+}
+
+export default withList
--
cgit v1.2.3-70-g09d2