Add withList hoc and remove UserList component
This commit is contained in:
parent
a817cc7cb4
commit
94e6de11b7
4 changed files with 30 additions and 22 deletions
27
src/hocs/with_list/with_list.js
Normal file
27
src/hocs/with_list/with_list.js
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue