diff options
| author | taehoon <th.dev91@gmail.com> | 2019-02-13 21:21:56 -0500 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-02-20 13:30:30 -0500 |
| commit | 09315b27804beadb7590f8e908ae9d0eb1d6a992 (patch) | |
| tree | 418d09834a43ee977186513b44a09882f1152d2e /src/hocs/with_subscription/with_subscription.js | |
| parent | 8c8a6edc7800bac854ef23f29aa87f5b932cb415 (diff) | |
Add a prop to force-refresh data to withSubscription hoc
Diffstat (limited to 'src/hocs/with_subscription/with_subscription.js')
| -rw-r--r-- | src/hocs/with_subscription/with_subscription.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/hocs/with_subscription/with_subscription.js b/src/hocs/with_subscription/with_subscription.js index 31fc106f..633517e3 100644 --- a/src/hocs/with_subscription/with_subscription.js +++ b/src/hocs/with_subscription/with_subscription.js @@ -1,24 +1,25 @@ import Vue from 'vue' -import filter from 'lodash/filter' +import reject from 'lodash/reject' import isEmpty from 'lodash/isEmpty' +import omit from 'lodash/omit' import './with_subscription.scss' const withSubscription = (Component, fetch, select, contentPropName = 'content') => { const originalProps = Component.props || [] - const props = filter(originalProps, v => v !== 'content') + const props = reject(originalProps, v => v === 'content') return Vue.component('withSubscription', { render (createElement) { const props = { props: { - ...this.$props, + ...omit(this.$props, 'refresh'), [contentPropName]: this.fetchedData }, on: this.$listeners } return ( <div class="with-subscription"> - <Component {...props} /> + {!this.error && !this.loading && <Component {...props} />} <div class="with-subscription-footer"> {this.error && <a onClick={this.fetchData} class="alert error">{this.$t('general.generic_error')}</a>} {!this.error && this.loading && <i class="icon-spin3 animate-spin"/>} @@ -26,7 +27,7 @@ const withSubscription = (Component, fetch, select, contentPropName = 'content') </div> ) }, - props, + props: [...props, 'refresh'], data () { return { loading: false, @@ -39,7 +40,7 @@ const withSubscription = (Component, fetch, select, contentPropName = 'content') } }, created () { - if (isEmpty(this.fetchedData)) { + if (this.refresh || isEmpty(this.fetchedData)) { this.fetchData() } }, |
