properly implement resettableAsyncComponent
This commit is contained in:
parent
9afbb12f95
commit
f21dc21a83
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
emits: ['resetAsyncComponent'],
|
||||||
methods: {
|
methods: {
|
||||||
retry () {
|
retry () {
|
||||||
this.$emit('resetAsyncComponent')
|
this.$emit('resetAsyncComponent')
|
||||||
|
|
|
@ -56,8 +56,8 @@ const SettingsModal = {
|
||||||
SettingsModalContent: getResettableAsyncComponent(
|
SettingsModalContent: getResettableAsyncComponent(
|
||||||
() => import('./settings_modal_content.vue'),
|
() => import('./settings_modal_content.vue'),
|
||||||
{
|
{
|
||||||
loading: PanelLoading,
|
loadingComponent: PanelLoading,
|
||||||
error: AsyncComponentError,
|
errorComponent: AsyncComponentError,
|
||||||
delay: 0
|
delay: 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// TODO investigate if even necessary since VUE3
|
import { defineAsyncComponent, shallowReactive, h } from 'vue'
|
||||||
import { reactive } from 'vue'
|
|
||||||
|
|
||||||
/* By default async components don't have any way to recover, if component is
|
/* 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
|
* 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.
|
* actual target component itself if needs to be.
|
||||||
*/
|
*/
|
||||||
function getResettableAsyncComponent (asyncComponent, options) {
|
function getResettableAsyncComponent (asyncComponent, options) {
|
||||||
const asyncComponentFactory = () => () => ({
|
const asyncComponentFactory = () => () => defineAsyncComponent({
|
||||||
component: asyncComponent(),
|
loader: asyncComponent,
|
||||||
...options
|
...options
|
||||||
})
|
})
|
||||||
|
|
||||||
const observe = reactive({ c: asyncComponentFactory() })
|
const observe = shallowReactive({ c: asyncComponentFactory() })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
functional: true,
|
render () {
|
||||||
render (createElement, { data, children }) {
|
|
||||||
// emit event resetAsyncComponent to reloading
|
// emit event resetAsyncComponent to reloading
|
||||||
data.on = {}
|
return h(observe.c(), {
|
||||||
data.on.resetAsyncComponent = () => {
|
onResetAsyncComponent () {
|
||||||
observe.c = asyncComponentFactory()
|
observe.c = asyncComponentFactory()
|
||||||
// parent.$forceUpdate()
|
}
|
||||||
}
|
})
|
||||||
return createElement(observe.c, data, children)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue