logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

resettable_async_component.js (1021B)


  1. import { defineAsyncComponent, shallowReactive, h } from 'vue'
  2. /* By default async components don't have any way to recover, if component is
  3. * failed, it is failed forever. This helper tries to remedy that by recreating
  4. * async component when retry is requested (by user). You need to emit the
  5. * `resetAsyncComponent` event from child to reset the component. Generally,
  6. * this should be done from error component but could be done from loading or
  7. * actual target component itself if needs to be.
  8. */
  9. function getResettableAsyncComponent (asyncComponent, options) {
  10. const asyncComponentFactory = () => () => defineAsyncComponent({
  11. loader: asyncComponent,
  12. ...options
  13. })
  14. const observe = shallowReactive({ c: asyncComponentFactory() })
  15. return {
  16. render () {
  17. // emit event resetAsyncComponent to reloading
  18. return h(observe.c(), {
  19. onResetAsyncComponent () {
  20. observe.c = asyncComponentFactory()
  21. }
  22. })
  23. }
  24. }
  25. }
  26. export default getResettableAsyncComponent