Pass down slots into wrapped components

This commit is contained in:
taehoon 2019-02-14 03:12:52 -05:00
parent 6d4d705c51
commit 8680046c4e
2 changed files with 36 additions and 18 deletions

View file

@ -18,11 +18,15 @@ const withLoadMore = ({
...this.$props, ...this.$props,
[childPropName]: this.entries [childPropName]: this.entries
}, },
on: this.$listeners on: this.$listeners,
scopedSlots: this.$scopedSlots
} }
const children = Object.keys(this.$slots).map(slot => createElement('template', { slot }, this.$slots[slot]))
return ( return (
<div class="with-load-more"> <div class="with-load-more">
<WrappedComponent {...props} /> <WrappedComponent {...props}>
{children}
</WrappedComponent>
<div class="with-load-more-footer"> <div class="with-load-more-footer">
{this.error && <a onClick={this.fetchEntries} class="alert error">{this.$t('general.generic_error')}</a>} {this.error && <a onClick={this.fetchEntries} class="alert error">{this.$t('general.generic_error')}</a>}
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>} {!this.error && this.loading && <i class="icon-spin3 animate-spin"/>}

View file

@ -13,25 +13,39 @@ const withSubscription = ({
const props = reject(originalProps, v => v === 'content') const props = reject(originalProps, v => v === 'content')
return Vue.component('withSubscription', { return Vue.component('withSubscription', {
props: [
...props,
'refresh' // boolean saying to force-fetch data whenever created
],
render (createElement) { render (createElement) {
const props = { if (!this.error && !this.loading) {
props: { const props = {
...omit(this.$props, 'refresh'), props: {
[childPropName]: this.fetchedData ...omit(this.$props, 'refresh'),
}, [childPropName]: this.fetchedData
on: this.$listeners },
} on: this.$listeners,
return ( scopedSlots: this.$scopedSlots
<div class="with-subscription"> }
{!this.error && !this.loading && <WrappedComponent {...props} />} const children = Object.keys(this.$slots).map(slot => createElement('template', { slot }, this.$slots[slot]))
<div class="with-subscription-footer"> return (
{this.error && <a onClick={this.fetchData} class="alert error">{this.$t('general.generic_error')}</a>} <div class="with-subscription">
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>} <WrappedComponent {...props}>
{children}
</WrappedComponent>
</div> </div>
</div> )
) } else {
return (
<div class="with-subscription-loading">
{this.error
? <a onClick={this.fetchData} class="alert error">{this.$t('general.generic_error')}</a>
: <i class="icon-spin3 animate-spin"/>
}
</div>
)
}
}, },
props: [...props, 'refresh'],
data () { data () {
return { return {
loading: false, loading: false,