diff options
| author | HJ <30-hj@users.noreply.git.pleroma.social> | 2020-06-06 21:24:47 +0000 |
|---|---|---|
| committer | HJ <30-hj@users.noreply.git.pleroma.social> | 2020-06-06 21:24:47 +0000 |
| commit | a5de8db579f6c50c1bbe5659e82bc29eaa588e7f (patch) | |
| tree | 9ab84c6012e3cb68484514920817862b91f1c25d /src/services/resettable_async_component.js | |
| parent | e47d0f210317c6e04e15fb89eb8f1d469137b779 (diff) | |
| parent | 68482fd3a6870514c7e8bd0fe433f24711e97ce9 (diff) | |
Merge branch 'settings-modal' into 'develop'
Settings modal
See merge request pleroma/pleroma-fe!1118
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 |
