diff options
| author | Henry Jameson <me@hjkos.com> | 2020-05-25 16:11:05 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2020-05-25 16:11:05 +0300 |
| commit | 7951192cd98263a2e5c9e1010f1299c651f82cef (patch) | |
| tree | 771dc48c3f6a480c752257d59eb8d09636b59f7a /src/services/resettable_async_component.js | |
| parent | a6ca923a7695477f57367bf3dd95bdf41a4b64a4 (diff) | |
Improve settings-modal async loading, update vue to 2.6.11 to be able
to use Vue.observable, to implmement resettable async component
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 |
