diff options
| author | Maksim Pechnikov <parallel588@gmail.com> | 2020-06-18 08:47:50 +0300 |
|---|---|---|
| committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-06-18 08:47:50 +0300 |
| commit | 08444c390348076231f15bd84b613cf39380bb72 (patch) | |
| tree | 4e00c479c37a052e51c8d081a76b0d03b3986127 /src/services/resettable_async_component.js | |
| parent | e3d0b2f137ccb355c16788e9b890df609cee1698 (diff) | |
| parent | 57626c125d0477716a638854c4243ee0fde96923 (diff) | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma-fe into develop
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 |
