diff options
| author | lain <lain@soykaf.club> | 2020-06-24 17:50:05 +0200 |
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-06-24 17:50:05 +0200 |
| commit | 143da55c56a932e4e88b4959511c59f1d73d37b9 (patch) | |
| tree | 598cce65273b759d7b064fceaaab20b172d541d3 /src/services/resettable_async_component.js | |
| parent | 7dfa734665bbb74058e221af0f71a88b4f37936d (diff) | |
| parent | bbb91d8ae3f1c3d5374de7610e723e63121e8222 (diff) | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma-fe into remove-twitterapi-config
Diffstat (limited to 'src/services/resettable_async_component.js')
| -rw-r--r-- | src/services/resettable_async_component.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/services/resettable_async_component.js b/src/services/resettable_async_component.js new file mode 100644 index 00000000..517bbd88 --- /dev/null +++ b/src/services/resettable_async_component.js @@ -0,0 +1,32 @@ +import Vue from 'vue' + +/* By default async components don't have any way to recover, if component is + * failed, it is failed forever. This helper tries to remedy that by recreating + * async component when retry is requested (by user). You need to emit the + * `resetAsyncComponent` event from child to reset the component. Generally, + * this should be done from error component but could be done from loading or + * actual target component itself if needs to be. + */ +function getResettableAsyncComponent (asyncComponent, options) { + const asyncComponentFactory = () => () => ({ + component: asyncComponent(), + ...options + }) + + const observe = Vue.observable({ c: asyncComponentFactory() }) + + return { + functional: true, + render (createElement, { data, children }) { + // emit event resetAsyncComponent to reloading + data.on = {} + data.on.resetAsyncComponent = () => { + observe.c = asyncComponentFactory() + // parent.$forceUpdate() + } + return createElement(observe.c, data, children) + } + } +} + +export default getResettableAsyncComponent |
