1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-28 06:48:36 +09:00

EventBus -> EventEmitter3

This commit is contained in:
NoriDev 2023-09-12 17:39:26 +09:00
parent 7dc732d38d
commit 0b8569edb9
22 changed files with 38 additions and 57 deletions

View File

@ -40,6 +40,7 @@
- 메모리 할당자를 jemalloc으로 설정 (MisskeyIO/misskey#152)
- 신고 즉시 해결 기능 (misskey-dev/misskey#11032)
- 어떤 이유로 클라이언트의 이모티콘 캐시가 삭제된 경우 즉시 다시 가져오도록 (MisskeyIO/misskey#163)
- EventBus를 사용하는 코드를 EventEmitter3로 변경
### Client
- about-misskey 페이지에서 클라이언트 버전을 누르면 변경 사항을 볼 수 있음

View File

@ -52,7 +52,6 @@
"is-file-animated": "1.0.2",
"json5": "2.2.3",
"matter-js": "0.19.0",
"mitt": "3.0.0",
"photoswipe": "5.3.9",
"prismjs": "1.29.0",
"punycode": "2.3.0",

View File

@ -34,7 +34,7 @@ import { miLocalStorage } from '@/local-storage';
import { mainRouter } from '@/router';
import { defaultStore } from '@/store';
import { deviceKind } from '@/scripts/device-kind';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const MOBILE_THRESHOLD = 500;
@ -101,7 +101,7 @@ onMounted(() => {
_bg.setAlpha(0.85);
bg.value = _bg.toRgbString();
eventBus.on('showEl', (showEl_receive) => {
globalEvents.on('showEl', (showEl_receive) => {
showEl = showEl_receive;
});
});

View File

@ -45,7 +45,7 @@ import { i18n } from '@/i18n';
import { claimAchievement } from '@/scripts/achievements';
import { $i } from '@/account';
import { userName } from '@/filters/user';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
let showFollowButton = $ref(false);
@ -138,7 +138,7 @@ onMounted(() => {
connection.on('unfollow', onFollowChange);
showFollowButton = $i != null && $i.id !== props.user.id;
eventBus.emit('showFollowButton', showFollowButton);
globalEvents.emit('showFollowButton', showFollowButton);
});
onBeforeUnmount(() => {

View File

@ -202,7 +202,7 @@ import { getNoteSummary } from '@/scripts/get-note-summary';
import MkRippleEffect from '@/components/MkRippleEffect.vue';
import { showMovedDialog } from '@/scripts/show-moved-dialog';
import { shouldCollapsed, shouldMfmCollapsed } from '@/scripts/collapsed';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import { mainRouter } from '@/router';
import { notePage } from '@/filters/note';
import { miLocalStorage } from '@/local-storage';
@ -271,7 +271,7 @@ const keymap = {
};
onMounted(() => {
eventBus.on('showEl', (showEl_receive) => {
globalEvents.on('showEl', (showEl_receive) => {
showEl = showEl_receive;
});
});

View File

@ -32,7 +32,7 @@ import MkSubNoteContent from '@/components/MkSubNoteContent.vue';
import MkCwButton from '@/components/MkCwButton.vue';
import MkEvent from '@/components/MkEvent.vue';
import { $i } from '@/account';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import { mainRouter } from '@/router';
import { defaultStore } from '@/store';
@ -45,7 +45,7 @@ const props = defineProps<{
const showContent = $ref(false);
onMounted(() => {
eventBus.on('showEl', (showEl_receive) => {
globalEvents.on('showEl', (showEl_receive) => {
showEl = showEl_receive;
});
});

View File

@ -74,7 +74,7 @@ import * as os from '@/os';
import { defaultStore } from '@/store';
import { miLocalStorage } from '@/local-storage';
import { unisonReload } from '@/scripts/unison-reload';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const fontSizeBefore = ref(miLocalStorage.getItem('fontSize'));
const useBoldFont = ref(miLocalStorage.getItem('useBoldFont'));
@ -88,7 +88,7 @@ async function reloadAsk() {
if (canceled) return;
unisonReload();
} else eventBus.emit('hasRequireRefresh', true);
} else globalEvents.emit('hasRequireRefresh', true);
}
const fontSize = computed(defaultStore.makeGetterSetter('fontSize'));

View File

@ -66,7 +66,6 @@ import * as os from '@/os';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
import MkFollowButton from '@/components/MkFollowButton.vue';
import { eventBus } from '@/scripts/cherrypick/eventBus';
let showFollowButton = $ref(false);
@ -219,7 +218,7 @@ onMounted(() => {
calcBg();
globalEvents.on('themeChanged', calcBg);
eventBus.on('showFollowButton', (showFollowButton_receive) => {
globalEvents.on('showFollowButton', (showFollowButton_receive) => {
showFollowButton = showFollowButton_receive;
});
});

View File

@ -64,7 +64,6 @@ import * as os from '@/os';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
import MkFollowButton from '@/components/MkFollowButton.vue';
import { eventBus } from '@/scripts/cherrypick/eventBus';
let showFollowButton = $ref(false);
@ -161,7 +160,7 @@ onMounted(() => {
calcBg();
globalEvents.on('themeChanged', calcBg);
eventBus.on('showFollowButton', (showFollowButton_receive) => {
globalEvents.on('showFollowButton', (showFollowButton_receive) => {
showFollowButton = showFollowButton_receive;
});
});

View File

@ -24,7 +24,7 @@ import { CURRENT_STICKY_BOTTOM, CURRENT_STICKY_TOP } from '@/const';
import { deviceKind } from '@/scripts/device-kind';
import { mainRouter } from '@/router';
import { defaultStore } from '@/store';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import { miLocalStorage } from '@/local-storage';
const isFriendly = ref(miLocalStorage.getItem('ui') === 'friendly');
@ -101,7 +101,7 @@ onMounted(() => {
observer.observe(headerEl);
observer.observe(footerEl);
eventBus.on('showEl', (showEl_receive) => {
globalEvents.on('showEl', (showEl_receive) => {
showEl = showEl_receive;
});
});

View File

@ -220,7 +220,7 @@ import { i18n } from '@/i18n';
import { iAmAdmin, $i } from '@/account';
import MkRolePreview from '@/components/MkRolePreview.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const props = withDefaults(defineProps<{
userId: string;
@ -447,7 +447,7 @@ watch($$(user), () => {
});
onMounted(() => {
eventBus.on('refreshUser', () => updateRemoteUser());
globalEvents.on('refreshUser', () => updateRemoteUser());
});
const headerActions = $computed(() => []);

View File

@ -37,7 +37,7 @@ import { useRouter } from '@/router';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { $i } from '@/account';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import MkChatPreview from '@/components/MkChatPreview.vue';
import MkPagination from '@/components/MkPagination.vue';
@ -148,7 +148,7 @@ onMounted(() => {
});
});
eventBus.on('openMessage', (ev) => {
globalEvents.on('openMessage', (ev) => {
start(ev);
});
});

View File

@ -281,7 +281,6 @@ import { definePageMetadata } from '@/scripts/page-metadata';
import { miLocalStorage } from '@/local-storage';
import { globalEvents } from '@/events';
import { claimAchievement } from '@/scripts/achievements';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import MkInfo from '@/components/MkInfo.vue';
const lang = ref(miLocalStorage.getItem('lang'));
@ -300,7 +299,7 @@ async function reloadAsk() {
if (canceled) return;
unisonReload();
} else eventBus.emit('hasRequireRefresh', true);
} else globalEvents.emit('hasRequireRefresh', true);
}
const overridedDeviceKind = computed(defaultStore.makeGetterSetter('overridedDeviceKind'));

View File

@ -67,7 +67,7 @@ import { defaultStore } from '@/store';
import { unisonReload } from '@/scripts/unison-reload';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
@ -88,7 +88,7 @@ async function reloadAsk() {
if (canceled) return;
unisonReload();
} else eventBus.emit('hasRequireRefresh', true);
} else globalEvents.emit('hasRequireRefresh', true);
}
async function addItem(ev: MouseEvent) {

View File

@ -90,7 +90,7 @@ import { signout, $i } from '@/account';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
import { unisonReload } from '@/scripts/unison-reload';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import FormSection from '@/components/form/section.vue';
const reportError = computed(defaultStore.makeGetterSetter('reportError'));
@ -140,7 +140,7 @@ async function reloadAsk() {
if (canceled) return;
unisonReload();
} else eventBus.emit('hasRequireRefresh', true);
} else globalEvents.emit('hasRequireRefresh', true);
}
watch([

View File

@ -59,7 +59,7 @@ import { $i } from '@/account';
import { definePageMetadata } from '@/scripts/page-metadata';
import { antennasCache, userListsCache } from '@/cache';
import { miLocalStorage } from '@/local-storage';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import { deviceKind } from '@/scripts/device-kind';
import { unisonReload } from '@/scripts/unison-reload';
@ -98,14 +98,14 @@ watch ($$(src), () => {
});
onMounted(() => {
eventBus.on('showEl', (showEl_receive) => {
globalEvents.on('showEl', (showEl_receive) => {
showEl = showEl_receive;
});
});
function queueUpdated(q: number): void {
queue = q;
eventBus.emit('queueUpdated', q);
globalEvents.emit('queueUpdated', q);
}
function top(): void {
@ -176,7 +176,7 @@ async function reloadAsk() {
if (canceled) return;
unisonReload();
} else eventBus.emit('hasRequireRefresh', true);
} else globalEvents.emit('hasRequireRefresh', true);
}
const headerActions = $computed(() => [{

View File

@ -1,8 +0,0 @@
/*
* SPDX-FileCopyrightText: noridev and other cherrypick contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import mitt from 'mitt';
export const eventBus = mitt();

View File

@ -16,7 +16,7 @@ import { mainRouter } from '@/router';
import { Router } from '@/nirax';
import { antennasCache, rolesCache, userListsCache } from '@/cache';
import { editNickname } from '@/scripts/edit-nickname';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
export function getUserMenu(user: Misskey.entities.UserDetailed, router: Router = mainRouter) {
const meId = $i ? $i.id : null;
@ -111,7 +111,7 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: Router
}
function refreshUser() {
eventBus.emit('refreshUser');
globalEvents.emit('refreshUser');
}
async function updateRemoteUser() {

View File

@ -27,7 +27,7 @@ import { i18n } from '@/i18n';
import MkButton from '@/components/MkButton.vue';
import * as os from '@/os';
import { defaultStore } from '@/store';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const zIndex = os.claimZIndex('high');
@ -53,7 +53,7 @@ function reload() {
useStream().on('_disconnected_', onDisconnected);
onMounted(() => {
eventBus.on('hasRequireRefresh', (hasRequireRefresh_receive) => {
globalEvents.on('hasRequireRefresh', (hasRequireRefresh_receive) => {
hasRequireRefresh = hasRequireRefresh_receive;
});
});

View File

@ -114,11 +114,10 @@ import { mainRouter } from '@/router';
import { PageMetadata, provideMetadataReceiver } from '@/scripts/page-metadata';
import { deviceKind } from '@/scripts/device-kind';
import { miLocalStorage } from '@/local-storage';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
import { CURRENT_STICKY_BOTTOM } from '@/const';
import { useScrollPositionManager } from '@/nirax';
import CPAvatar from '@/components/global/CPAvatar-Friendly.vue';
import { globalEvents } from '@/events';
const XWidgets = defineAsyncComponent(() => import('./universal.widgets.vue'));
const XNotifications = defineAsyncComponent(() => import('@/pages/notifications.vue'));
@ -236,7 +235,7 @@ onMounted(() => {
contents.value.rootEl.addEventListener('scroll', onScroll);
eventBus.on('queueUpdated', (q) => queueUpdated(q));
globalEvents.on('queueUpdated', (q) => queueUpdated(q));
calcBg();
globalEvents.on('themeChanged', calcBg);
@ -263,7 +262,7 @@ function onScroll() {
showEl = currentScrollPosition < lastScrollPosition;
lastScrollPosition = currentScrollPosition;
showEl = !showEl;
eventBus.emit('showEl', showEl);
globalEvents.emit('showEl', showEl);
}
const onContextmenu = (ev) => {
@ -316,7 +315,7 @@ function closeAccountMenu() {
}
function openMessage(ev: MouseEvent) {
if (mainRouter.currentRoute.value.name === 'messaging' && !(['messaging-room', 'messaging-room-group'].includes(<string>mainRouter.currentRoute.value.name))) eventBus.emit('openMessage', ev);
if (mainRouter.currentRoute.value.name === 'messaging' && !(['messaging-room', 'messaging-room-group'].includes(<string>mainRouter.currentRoute.value.name))) globalEvents.emit('openMessage', ev);
else if (enablePostButton.includes(<string>mainRouter.currentRoute.value.name)) os.post();
}

View File

@ -106,7 +106,7 @@ import { deviceKind } from '@/scripts/device-kind';
import { miLocalStorage } from '@/local-storage';
import { CURRENT_STICKY_BOTTOM } from '@/const';
import { useScrollPositionManager } from '@/nirax';
import { eventBus } from '@/scripts/cherrypick/eventBus';
import { globalEvents } from '@/events';
const XWidgets = defineAsyncComponent(() => import('./universal.widgets.vue'));
const XSidebar = defineAsyncComponent(() => import('@/ui/_common_/navbar.vue'));
@ -204,7 +204,7 @@ function onScroll() {
showEl = currentScrollPosition < lastScrollPosition;
lastScrollPosition = currentScrollPosition;
showEl = !showEl;
eventBus.emit('showEl', showEl);
globalEvents.emit('showEl', showEl);
}
const onContextmenu = (ev) => {

View File

@ -818,9 +818,6 @@ importers:
matter-js:
specifier: 0.19.0
version: 0.19.0
mitt:
specifier: 3.0.0
version: 3.0.0
photoswipe:
specifier: 5.3.9
version: 5.3.9
@ -15748,10 +15745,6 @@ packages:
minipass: 3.3.6
yallist: 4.0.0
/mitt@3.0.0:
resolution: {integrity: sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==}
dev: false
/mkdirp-classic@0.5.3:
resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==}