aboutsummaryrefslogtreecommitdiff
path: root/src/services/resettable_async_component.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2022-03-28 23:55:26 +0300
committerHenry Jameson <me@hjkos.com>2022-03-28 23:55:57 +0300
commitf21dc21a83cbcf4c502b8fbf56cabac797a0b9da (patch)
treed562e08e92fe15f095a0f05da8b419b546057a47 /src/services/resettable_async_component.js
parent9afbb12f956434f0426a00d311406ddd8348c892 (diff)
properly implement resettableAsyncComponent
Diffstat (limited to 'src/services/resettable_async_component.js')
-rw-r--r--src/services/resettable_async_component.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/services/resettable_async_component.js b/src/services/resettable_async_component.js
index e85c540b..1c046ce7 100644
--- a/src/services/resettable_async_component.js
+++ b/src/services/resettable_async_component.js
@@ -1,5 +1,4 @@
-// TODO investigate if even necessary since VUE3
-import { reactive } from 'vue'
+import { defineAsyncComponent, shallowReactive, h } 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
@@ -9,23 +8,21 @@ import { reactive } from 'vue'
* actual target component itself if needs to be.
*/
function getResettableAsyncComponent (asyncComponent, options) {
- const asyncComponentFactory = () => () => ({
- component: asyncComponent(),
+ const asyncComponentFactory = () => () => defineAsyncComponent({
+ loader: asyncComponent,
...options
})
- const observe = reactive({ c: asyncComponentFactory() })
+ const observe = shallowReactive({ c: asyncComponentFactory() })
return {
- functional: true,
- render (createElement, { data, children }) {
+ render () {
// emit event resetAsyncComponent to reloading
- data.on = {}
- data.on.resetAsyncComponent = () => {
- observe.c = asyncComponentFactory()
- // parent.$forceUpdate()
- }
- return createElement(observe.c, data, children)
+ return h(observe.c(), {
+ onResetAsyncComponent () {
+ observe.c = asyncComponentFactory()
+ }
+ })
}
}
}