diff --git a/package-lock.json b/package-lock.json index a755100..e9856c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3186,9 +3186,9 @@ } }, "events": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", - "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/events/-/events-2.0.0.tgz", + "integrity": "sha512-r/M5YkNg9zwI8QbSf7tsDWWJvO3PGwZXyG7GpFAxtMASnHL2eblFd7iHiGPtyGKKFPZ59S63NeX10Ws6WqGDcg==" }, "evp_bytestokey": { "version": "1.0.3", @@ -6369,6 +6369,13 @@ "url": "0.11.0", "util": "0.10.3", "vm-browserify": "0.0.4" + }, + "dependencies": { + "events": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", + "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=" + } } }, "node-sass": { diff --git a/package.json b/package.json index 3eeb5c1..547ec2b 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "cross-env": "^5.1.3", "css-loader": "^0.28.7", "esm": "^3.0.12", + "events": "^2.0.0", "express": "^4.16.2", "fg-loadcss": "^2.0.1", "file-api": "^0.10.4", diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index 1ab6bea..d0c0a1b 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -3,6 +3,7 @@ import { toast } from '../_utils/toast' import { postStatus as postStatusToServer } from '../_api/statuses' import { addStatusOrNotification } from './addStatusOrNotification' import { database } from '../_database/database' +import { emit } from '../_utils/eventBus' export async function insertHandleForReply (statusId) { let instanceName = store.get('currentInstance') @@ -30,17 +31,14 @@ export async function postStatus (realm, text, inReplyToId, mediaIds, } store.set({ - postingStatus: true, - postedStatusForRealm: null + postingStatus: true }) try { let status = await postStatusToServer(instanceName, accessToken, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility) addStatusOrNotification(instanceName, 'home', status) store.clearComposeData(realm) - store.set({ - postedStatusForRealm: realm - }) + emit('postedStatus', realm) } catch (e) { console.error(e) toast.say('Unable to post status: ' + (e.message || '')) diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index 6d179de..19a4113 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -126,13 +126,6 @@ // make sure the visibility is consistent with the replied-to status setReplyVisibility(realm, replyVisibility) } - - this.observe('postedStatusForRealm', postedStatusForRealm => { - if (postedStatusForRealm !== realm) { - return - } - this.fire('postedStatus') - }, {init: false}) }, ondestroy() { this.teardownStickyObserver() @@ -177,7 +170,6 @@ overLimit: (length) => length > CHAR_LIMIT, contentWarningShown: (composeData) => composeData.contentWarningShown, contentWarning: (composeData) => composeData.contentWarning || '', - postedStatusForRealm: ($postedStatusForRealm) => $postedStatusForRealm, timelineInitialized: ($timelineInitialized) => $timelineInitialized }, transitions: { diff --git a/routes/_components/compose/ComposeInput.html b/routes/_components/compose/ComposeInput.html index bd6b73d..5a17b1f 100644 --- a/routes/_components/compose/ComposeInput.html +++ b/routes/_components/compose/ComposeInput.html @@ -166,9 +166,6 @@ data: () => ({ rawText: '' }), - computed: { - postedStatusForRealm: ($postedStatusForRealm) => $postedStatusForRealm - }, events: { selectionChange } diff --git a/routes/_components/dialog/ComposeDialog.html b/routes/_components/dialog/ComposeDialog.html index c511477..eb947cc 100644 --- a/routes/_components/dialog/ComposeDialog.html +++ b/routes/_components/dialog/ComposeDialog.html @@ -6,13 +6,17 @@ background="var(--main-bg)" on:destroyDialog="destroy()" > - + \ No newline at end of file diff --git a/routes/_utils/eventBus.js b/routes/_utils/eventBus.js new file mode 100644 index 0000000..a542a31 --- /dev/null +++ b/routes/_utils/eventBus.js @@ -0,0 +1,17 @@ +import EventEmitter from 'events' + +const eventBus = new EventEmitter() + +if (process.browser && process.env.NODE_ENV !== 'production') { + window.eventBus = eventBus +} + +export function on (eventName, component, method) { + let callback = method.bind(component) + eventBus.on(eventName, callback) + component.on('destroy', () => { + eventBus.removeListener(eventName, callback) + }) +} + +export const emit = eventBus.emit.bind(eventBus)