Skip to content

Commit

Permalink
pref: Optimize client imports (#9506)
Browse files Browse the repository at this point in the history
* pref: Optimize client imports

* split api?

* fix

* ✌️

* no vue split?

* Revert "no vue split?"

This reverts commit 27ccec9.

* function => const

* ✌️

* Revert "function => const"

This reverts commit 34f2feb.

* function api
  • Loading branch information
tamaina authored Jan 17, 2023
1 parent 424919f commit d456308
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
39 changes: 23 additions & 16 deletions packages/frontend/src/os.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// TODO: なんでもかんでもos.tsに突っ込むのやめたいのでよしなに分割する

import { pendingApiRequestsCount, api, apiGet } from '@/scripts/api';
export { pendingApiRequestsCount, api, apiGet };
import { Component, markRaw, Ref, ref, defineAsyncComponent } from 'vue';
import { EventEmitter } from 'eventemitter3';
import insertTextAtCursor from 'insert-text-at-cursor';
import * as Misskey from 'misskey-js';
import { i18n } from './i18n';
import MkPostFormDialog from '@/components/MkPostFormDialog.vue';
import MkWaitingDialog from '@/components/MkWaitingDialog.vue';
import MkPageWindow from '@/components/MkPageWindow.vue'
import MkToast from '@/components/MkToast.vue';
import MkDialog from '@/components/MkDialog.vue';
import MkEmojiPickerDialog from '@/components/MkEmojiPickerDialog.vue';
import MkEmojiPickerWindow from '@/components/MkEmojiPickerWindow.vue';
import MkPopupMenu from '@/components/MkPopupMenu.vue';
import MkContextMenu from '@/components/MkContextMenu.vue';
import { MenuItem } from '@/types/menu';
import { pendingApiRequestsCount, api, apiGet } from '@/scripts/api';
export { pendingApiRequestsCount, api, apiGet };

export const apiWithDialog = ((
endpoint: string,
Expand Down Expand Up @@ -124,7 +131,7 @@ export async function popup(component: Component, props: Record<string, any>, ev
}

export function pageWindow(path: string) {
popup(defineAsyncComponent(() => import('@/components/MkPageWindow.vue')), {
popup(MkPageWindow, {
initialPath: path,
}, {}, 'closed');
}
Expand All @@ -136,7 +143,7 @@ export function modalPageWindow(path: string) {
}

export function toast(message: string) {
popup(defineAsyncComponent(() => import('@/components/MkToast.vue')), {
popup(MkToast, {
message,
}, {}, 'closed');
}
Expand All @@ -147,7 +154,7 @@ export function alert(props: {
text?: string | null;
}): Promise<void> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), props, {
popup(MkDialog, props, {
done: result => {
resolve();
},
Expand All @@ -161,7 +168,7 @@ export function confirm(props: {
text?: string | null;
}): Promise<{ canceled: boolean }> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
...props,
showCancelButton: true,
}, {
Expand All @@ -182,7 +189,7 @@ export function inputText(props: {
canceled: false; result: string;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
Expand All @@ -207,7 +214,7 @@ export function inputNumber(props: {
canceled: false; result: number;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
Expand All @@ -232,7 +239,7 @@ export function inputDate(props: {
canceled: false; result: Date;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
Expand Down Expand Up @@ -269,7 +276,7 @@ export function select<C = any>(props: {
canceled: false; result: C;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
select: {
Expand All @@ -291,7 +298,7 @@ export function success() {
window.setTimeout(() => {
showing.value = false;
}, 1000);
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
popup(MkWaitingDialog, {
success: true,
showing: showing,
}, {
Expand All @@ -303,7 +310,7 @@ export function success() {
export function waiting() {
return new Promise((resolve, reject) => {
const showing = ref(true);
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
popup(MkWaitingDialog, {
success: false,
showing: showing,
}, {
Expand Down Expand Up @@ -366,7 +373,7 @@ export async function selectDriveFolder(multiple: boolean) {

export async function pickEmoji(src: HTMLElement | null, opts) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerDialog.vue')), {
popup(MkEmojiPickerDialog, {
src,
...opts,
}, {
Expand Down Expand Up @@ -431,7 +438,7 @@ export async function openEmojiPicker(src?: HTMLElement, opts, initialTextarea:
characterData: false,
});

openingEmojiPicker = await popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerWindow.vue')), {
openingEmojiPicker = await popup(MkEmojiPickerWindow, {
src,
...opts,
}, {
Expand All @@ -454,7 +461,7 @@ export function popupMenu(items: MenuItem[] | Ref<MenuItem[]>, src?: HTMLElement
}) {
return new Promise((resolve, reject) => {
let dispose;
popup(defineAsyncComponent(() => import('@/components/MkPopupMenu.vue')), {
popup(MkPopupMenu, {
items,
src,
width: options?.width,
Expand All @@ -478,7 +485,7 @@ export function contextMenu(items: MenuItem[] | Ref<MenuItem[]>, ev: MouseEvent)
ev.preventDefault();
return new Promise((resolve, reject) => {
let dispose;
popup(defineAsyncComponent(() => import('@/components/MkContextMenu.vue')), {
popup(MkContextMenu, {
items,
ev,
}, {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function api<E extends keyof Endpoints, P extends Endpoints[E]['req']>(en
}

// Implements Misskey.api.ApiClient.request
export function apiGet<E extends keyof Endpoints, P extends Endpoints[E]['req']>(endpoint: E, data: P = {} as any): Promise<Endpoints[E]['res']> {
export function apiGet <E extends keyof Endpoints, P extends Endpoints[E]['req']>(endpoint: E, data: P = {} as any): Promise<Endpoints[E]['res']> {
pendingApiRequestsCount.value++;

const onFinally = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default defineConfig(({ command, mode }) => {
output: {
manualChunks: {
vue: ['vue'],
photoswipe: ['photoswipe', 'photoswipe/lightbox', 'photoswipe/style.css'],
},
},
},
Expand Down

0 comments on commit d456308

Please sign in to comment.