fix: remove svelte #await (#1501)

This commit is contained in:
Nolan Lawson 2019-09-20 18:53:04 -07:00 committed by GitHub
parent 78fa8c2873
commit ab9fc31405
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 35 deletions

View file

@ -13,13 +13,9 @@
{/each} {/each}
</ul> </ul>
</nav> </nav>
{#await importNavShortcuts} {#if navShortcuts}
<!-- awaiting nav shortcuts promise --> <svelte:component this={navShortcuts}/>
{:then component} {/if}
<svelte:component this={component}/>
{:catch error}
<!-- nav shortcuts {error} -->
{/await}
<style> <style>
.main-nav { .main-nav {
@ -58,12 +54,16 @@
import { store } from '../_store/store' import { store } from '../_store/store'
export default { export default {
async oncreate () {
const navShortcuts = await importNavShortcuts()
this.set({ navShortcuts })
},
store: () => store, store: () => store,
components: { components: {
NavItem NavItem
}, },
data: () => ({ data: () => ({
importNavShortcuts: importNavShortcuts() navShortcuts: undefined
}) })
} }
</script> </script>

View file

@ -1,16 +1,16 @@
{#await importComposeBox} {#if composeBox}
<!-- awaiting promise --> <svelte:component this={composeBox} {realm} {hidden} />
{:then ComposeBox} {/if}
<svelte:component this={ComposeBox} {realm} {hidden} />
{:catch error}
<div>Component failed to load. Try refreshing! {error}</div>
{/await}
<script> <script>
import { importComposeBox } from '../../_utils/asyncModules' import { importComposeBox } from '../../_utils/asyncModules'
export default { export default {
async oncreate () {
const composeBox = await importComposeBox()
this.set({ composeBox })
},
data: () => ({ data: () => ({
importComposeBox: importComposeBox() composeBox: undefined
}) })
} }
</script> </script>

View file

@ -1,11 +1,7 @@
<div class="lazy-timeline"> <div class="lazy-timeline">
{#await importTimeline} {#if timelineComponent}
<!-- awaiting promise --> <svelte:component this={timelineComponent} {timeline} />
{:then constructor} {/if}
<svelte:component this={constructor} {timeline} />
{:catch error}
<div>Component failed to load. Try refreshing! {error}</div>
{/await}
</div> </div>
<style> <style>
.lazy-timeline { .lazy-timeline {
@ -13,19 +9,24 @@
} }
</style> </style>
<script> <script>
import { importTimeline } from '../../_utils/asyncModules'
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { importTimeline } from '../../_utils/asyncModules'
export default { export default {
oncreate () { async oncreate () {
console.log('LazyTimeline oncreate')
const { currentInstance } = this.store.get() const { currentInstance } = this.store.get()
const { timeline } = this.get() const { timeline } = this.get()
this.store.set({ currentTimeline: timeline }) this.store.set({ currentTimeline: timeline })
this.store.setForTimeline(currentInstance, timeline, { runningUpdate: false }) this.store.setForTimeline(currentInstance, timeline, { runningUpdate: false })
console.log('importing timeline')
const timelineComponent = await importTimeline()
console.log('imported timeline')
this.set({ timelineComponent })
}, },
store: () => store, store: () => store,
data: () => ({ data: () => ({
importTimeline: importTimeline() timelineComponent: undefined
}) })
} }
</script> </script>

View file

@ -4,11 +4,9 @@
on:focusin="saveFocus(event)" on:focusin="saveFocus(event)"
on:focusout="clearFocus()" on:focusout="clearFocus()"
> >
{#await componentsPromise} {#if components}
<!-- awaiting promise --> <svelte:component this={components.listComponent}
{:then result} component={components.listItemComponent}
<svelte:component this={result.listComponent}
component={result.listItemComponent}
realm="{$currentInstance + '/' + timeline}" realm="{$currentInstance + '/' + timeline}"
{makeProps} {makeProps}
items={itemIds} items={itemIds}
@ -24,9 +22,7 @@
on:initialized="initialize()" on:initialized="initialize()"
on:noNeedToScroll="onNoNeedToScroll()" on:noNeedToScroll="onNoNeedToScroll()"
/> />
{:catch error} {/if}
<div>Error: component failed to load! Try reloading. {error}</div>
{/await}
</div> </div>
<Shortcut scope="global" key="." on:pressed="showMoreAndScrollToTop()" /> <Shortcut scope="global" key="." on:pressed="showMoreAndScrollToTop()" />
<ScrollListShortcuts /> <ScrollListShortcuts />
@ -66,6 +62,7 @@
setupTimeline() setupTimeline()
this.restoreFocus() this.restoreFocus()
this.setupStreaming() this.setupStreaming()
this.setupAsyncComponents()
}, },
ondestroy () { ondestroy () {
console.log('ondestroy') console.log('ondestroy')
@ -75,7 +72,8 @@
LoadingFooter, LoadingFooter,
MoreHeaderVirtualWrapper, MoreHeaderVirtualWrapper,
Status, Status,
scrollTop: 0 scrollTop: 0,
components: undefined
}), }),
computed: { computed: {
// For threads, it's simpler to just render all items as a pseudo-virtual list // For threads, it's simpler to just render all items as a pseudo-virtual list
@ -230,6 +228,16 @@
teardownFocus () { teardownFocus () {
window.removeEventListener('pushState', this.onPushState) window.removeEventListener('pushState', this.onPushState)
}, },
setupAsyncComponents () {
this.observe('componentsPromise', async componentsPromise => {
if (componentsPromise) {
console.log('loading timeline components')
const components = await componentsPromise
console.log('loaded timeline components')
this.set({ components })
}
})
},
onPushState () { onPushState () {
this.store.setForCurrentTimeline({ ignoreBlurEvents: true }) this.store.setForCurrentTimeline({ ignoreBlurEvents: true })
}, },