From 555d42f7a7fb1a0a5de4817ab580aa6400c825be Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 27 Apr 2022 00:15:10 +0900 Subject: [PATCH] wip use defineAsyncComponent --- packages/client/src/account.ts | 6 +++--- packages/client/src/init.ts | 2 +- packages/client/src/os.ts | 11 ++--------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index f4dcab319c..6f806ccc58 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -1,5 +1,5 @@ import { del, get, set } from '@/scripts/idb-proxy'; -import { reactive } from 'vue'; +import { defineAsyncComponent, reactive } from 'vue'; import * as misskey from 'misskey-js'; import { apiUrl } from '@/config'; import { waiting, api, popup, popupMenu, success, alert } from '@/os'; @@ -141,7 +141,7 @@ export async function openAccountMenu(opts: { onChoose?: (account: misskey.entities.UserDetailed) => void; }, ev: MouseEvent) { function showSigninDialog() { - popup(import('@/components/signin-dialog.vue'), {}, { + popup(defineAsyncComponent(() => import('@/components/signin-dialog.vue')), {}, { done: res => { addAccount(res.id, res.i); success(); @@ -150,7 +150,7 @@ export async function openAccountMenu(opts: { } function createAccount() { - popup(import('@/components/signup-dialog.vue'), {}, { + popup(defineAsyncComponent(() => import('@/components/signup-dialog.vue')), {}, { done: res => { addAccount(res.id, res.i); switchAccountWithToken(res.i); diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index 1fa9c2afe6..fd2104a8d7 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -230,7 +230,7 @@ if (lastVersion !== version) { if (lastVersion != null && compareVersions(version, lastVersion) === 1) { // ログインしてる場合だけ if ($i) { - popup(import('@/components/updated.vue'), {}, {}, 'closed'); + popup(defineAsyncComponent(() => import('@/components/updated.vue')), {}, {}, 'closed'); } } } catch (e) { diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index 43c110555f..2ab4ec28d6 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -111,10 +111,6 @@ export function promiseDialog>( return promise; } -function isModule(x: any): x is typeof import('*.vue') { - return x.default != null; -} - let popupIdCount = 0; export const popups = ref([]) as Ref<{ id: any; @@ -132,10 +128,7 @@ export function claimZIndex(priority: 'low' | 'middle' | 'high' = 'low'): number return zIndexes[priority]; } -export async function popup(component: Component | typeof import('*.vue') | Promise, props: Record, events = {}, disposeEvent?: string) { - if (component.then) component = await component; - - if (isModule(component)) component = component.default; +export async function popup(component: Component, props: Record, events = {}, disposeEvent?: string) { markRaw(component); const id = ++popupIdCount; @@ -164,7 +157,7 @@ export async function popup(component: Component | typeof import('*.vue') | Prom export function pageWindow(path: string) { const { component, props } = resolve(path); - popup(import('@/components/page-window.vue'), { + popup(defineAsyncComponent(() => import('@/components/page-window.vue')), { initialPath: path, initialComponent: markRaw(component), initialProps: props,