From 8d5690d63dc72c0574c373199b297f80ba38ed5b Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Thu, 19 Apr 2018 09:37:05 -0700 Subject: [PATCH] remove get() with string from Svelte calls (#169) * remove get() with string pt 1 * remove get() with string pt 2 * fix typo * fix some null exceptions in get() * fixup code style --- routes/_actions/accounts.js | 7 +- routes/_actions/addInstance.js | 29 ++++----- routes/_actions/block.js | 7 +- routes/_actions/compose.js | 38 +++++------ routes/_actions/delete.js | 5 +- routes/_actions/emoji.js | 21 +++--- routes/_actions/favorite.js | 16 ++--- routes/_actions/follow.js | 9 ++- routes/_actions/instances.js | 28 ++++---- routes/_actions/lists.js | 13 ++-- routes/_actions/media.js | 5 +- routes/_actions/mute.js | 7 +- routes/_actions/pinnedStatuses.js | 17 +++-- routes/_actions/reblog.js | 16 ++--- routes/_actions/search.js | 10 ++- routes/_actions/timeline.js | 30 +++++---- routes/_components/AccountsListPage.html | 2 +- routes/_components/IconButton.html | 3 +- routes/_components/LazyImage.html | 4 +- routes/_components/NavItem.html | 3 +- routes/_components/NonAutoplayImg.html | 7 +- .../_components/community/PageListItem.html | 5 +- .../compose/ComposeAutosuggest.html | 21 +++--- routes/_components/compose/ComposeBox.html | 27 ++++---- .../compose/ComposeContentWarning.html | 3 +- routes/_components/compose/ComposeInput.html | 39 ++++++----- .../compose/ComposeLengthGauge.html | 6 +- .../compose/ComposeLengthIndicator.html | 6 +- .../_components/compose/ComposeMediaItem.html | 14 ++-- .../_components/compose/ComposeToolbar.html | 11 ++-- .../AccountProfileOptionsDialog.html | 12 ++-- .../dialog/components/ConfirmationDialog.html | 20 ++++-- .../dialog/components/EmojiDialog.html | 3 +- .../dialog/components/ModalDialog.html | 13 ++-- .../dialog/components/PostPrivacyDialog.html | 3 +- .../components/StatusOptionsDialog.html | 11 ++-- .../_components/dialog/helpers/closeDialog.js | 2 +- .../dialog/helpers/onCreateDialog.js | 5 +- .../_components/dialog/helpers/showDialog.js | 2 +- .../profile/AccountProfileDetails.html | 4 +- .../profile/AccountProfileFollow.html | 12 ++-- .../pseudoVirtualList/PseudoVirtualList.html | 20 +++--- .../PseudoVirtualListItem.html | 6 +- .../PseudoVirtualListLazyItem.html | 3 +- routes/_components/status/Media.html | 20 +++--- routes/_components/status/Status.html | 9 +-- .../_components/status/StatusComposeBox.html | 11 ++-- routes/_components/status/StatusContent.html | 3 +- .../status/StatusMediaAttachments.html | 11 ++-- routes/_components/status/StatusSpoiler.html | 11 ++-- routes/_components/status/StatusToolbar.html | 39 ++++++----- routes/_components/timeline/LazyTimeline.html | 6 +- routes/_components/timeline/MoreHeader.html | 2 +- .../_components/timeline/PinnedStatuses.html | 2 +- routes/_components/timeline/Timeline.html | 64 +++++++++++-------- .../virtualList/VirtualListContainer.html | 19 ++++-- .../virtualList/VirtualListHeader.html | 3 +- .../virtualList/VirtualListItem.html | 6 +- .../virtualList/VirtualListLazyItem.html | 3 +- routes/_database/cleanup.js | 4 +- routes/_pages/accounts/[accountId].html | 3 +- routes/_pages/community/index.html | 3 +- routes/_pages/pinned.html | 8 +-- .../settings/instances/[instanceName].html | 9 ++- routes/_store/mixins/instanceMixins.js | 21 +++--- routes/_store/mixins/statusMixins.js | 2 +- routes/_store/mixins/timelineMixins.js | 10 ++- routes/_store/observers/instanceObservers.js | 11 ++-- routes/_store/observers/timelineObservers.js | 20 +++--- routes/_utils/RealmStore.js | 20 +++--- 70 files changed, 454 insertions(+), 391 deletions(-) diff --git a/routes/_actions/accounts.js b/routes/_actions/accounts.js index f8e98136..c90df722 100644 --- a/routes/_actions/accounts.js +++ b/routes/_actions/accounts.js @@ -52,11 +52,10 @@ export async function clearProfileAndRelationship () { } export async function updateProfileAndRelationship (accountId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await Promise.all([ - updateAccount(accountId, instanceName, accessToken), - updateRelationship(accountId, instanceName, accessToken) + updateAccount(accountId, currentInstance, accessToken), + updateRelationship(accountId, currentInstance, accessToken) ]) } diff --git a/routes/_actions/addInstance.js b/routes/_actions/addInstance.js index 8fe69f9e..69fcfc7e 100644 --- a/routes/_actions/addInstance.js +++ b/routes/_actions/addInstance.js @@ -11,24 +11,23 @@ const REDIRECT_URI = (typeof location !== 'undefined' ? location.origin : 'https://pinafore.social') + '/settings/instances/add' async function redirectToOauth () { - let instanceName = store.get('instanceNameInSearch') - let loggedInInstances = store.get('loggedInInstances') - instanceName = instanceName.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() - if (Object.keys(loggedInInstances).includes(instanceName)) { - store.set({logInToInstanceError: `You've already logged in to ${instanceName}`}) + let { instanceNameInSearch, loggedInInstances } = store.get() + instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() + if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) { + store.set({logInToInstanceError: `You've already logged in to ${instanceNameInSearch}`}) return } - let registrationPromise = registerApplication(instanceName, REDIRECT_URI) - let instanceInfo = await getInstanceInfo(instanceName) - await setInstanceInfoInDatabase(instanceName, instanceInfo) // cache for later + let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI) + let instanceInfo = await getInstanceInfo(instanceNameInSearch) + await setInstanceInfoInDatabase(instanceNameInSearch, instanceInfo) // cache for later let instanceData = await registrationPromise store.set({ - currentRegisteredInstanceName: instanceName, + currentRegisteredInstanceName: instanceNameInSearch, currentRegisteredInstance: instanceData }) store.save() let oauthUrl = generateAuthLink( - instanceName, + instanceNameInSearch, instanceData.client_id, REDIRECT_URI ) @@ -48,9 +47,10 @@ export async function logInToInstance () { (navigator.onLine ? `Is this a valid Mastodon instance? Is a browser extension blocking the request?` : `Are you offline?`) + let { instanceNameInSearch } = store.get() store.set({ logInToInstanceError: error, - logInToInstanceErrorForText: store.get('instanceNameInSearch') + logInToInstanceErrorForText: instanceNameInSearch }) } finally { store.set({logInToInstanceLoading: false}) @@ -58,8 +58,7 @@ export async function logInToInstance () { } async function registerNewInstance (code) { - let currentRegisteredInstanceName = store.get('currentRegisteredInstanceName') - let currentRegisteredInstance = store.get('currentRegisteredInstance') + let { currentRegisteredInstanceName, currentRegisteredInstance } = store.get() let instanceData = await getAccessTokenFromAuthCode( currentRegisteredInstanceName, currentRegisteredInstance.client_id, @@ -67,9 +66,7 @@ async function registerNewInstance (code) { code, REDIRECT_URI ) - let loggedInInstances = store.get('loggedInInstances') - let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') - let instanceThemes = store.get('instanceThemes') + let { loggedInInstances, loggedInInstancesInOrder, instanceThemes } = store.get() instanceThemes[currentRegisteredInstanceName] = 'default' loggedInInstances[currentRegisteredInstanceName] = instanceData if (!loggedInInstancesInOrder.includes(currentRegisteredInstanceName)) { diff --git a/routes/_actions/block.js b/routes/_actions/block.js index 07587757..850cce06 100644 --- a/routes/_actions/block.js +++ b/routes/_actions/block.js @@ -4,13 +4,12 @@ import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' export async function setAccountBlocked (accountId, block, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { if (block) { - await blockAccount(instanceName, accessToken, accountId) + await blockAccount(currentInstance, accessToken, accountId) } else { - await unblockAccount(instanceName, accessToken, accountId) + await unblockAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) if (toastOnSuccess) { diff --git a/routes/_actions/compose.js b/routes/_actions/compose.js index ae933f9d..5a763d11 100644 --- a/routes/_actions/compose.js +++ b/routes/_actions/compose.js @@ -7,12 +7,12 @@ import { emit } from '../_utils/eventBus' import { putMediaDescription } from '../_api/media' export async function insertHandleForReply (statusId) { - let instanceName = store.get('currentInstance') - let status = await getStatusFromDatabase(instanceName, statusId) - let verifyCredentials = store.get('currentVerifyCredentials') + let { currentInstance } = store.get() + let status = await getStatusFromDatabase(currentInstance, statusId) + let { currentVerifyCredentials } = store.get() let originalStatus = status.reblog || status let accounts = [originalStatus.account].concat(originalStatus.mentions || []) - .filter(account => account.id !== verifyCredentials.id) + .filter(account => account.id !== currentVerifyCredentials.id) if (!store.getComposeData(statusId, 'text') && accounts.length) { store.setComposeData(statusId, { text: accounts.map(account => `@${account.acct} `).join('') @@ -23,9 +23,7 @@ export async function insertHandleForReply (statusId) { export async function postStatus (realm, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility, mediaDescriptions = [], inReplyToUuid) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let online = store.get('online') + let { currentInstance, accessToken, online } = store.get() if (!online) { toast.say('You cannot post while offline') @@ -37,11 +35,11 @@ export async function postStatus (realm, text, inReplyToId, mediaIds, }) try { await Promise.all(mediaDescriptions.map(async (description, i) => { - return description && putMediaDescription(instanceName, accessToken, mediaIds[i], description) + return description && putMediaDescription(currentInstance, accessToken, mediaIds[i], description) })) - let status = await postStatusToServer(instanceName, accessToken, text, + let status = await postStatusToServer(currentInstance, accessToken, text, inReplyToId, mediaIds, sensitive, spoilerText, visibility) - addStatusOrNotification(instanceName, 'home', status) + addStatusOrNotification(currentInstance, 'home', status) store.clearComposeData(realm) emit('postedStatus', realm, inReplyToUuid) } catch (e) { @@ -61,12 +59,16 @@ export async function insertUsername (realm, username, startIndex, endIndex) { } export async function clickSelectedAutosuggestionUsername (realm) { - let selectionStart = store.get('composeSelectionStart') - let searchText = store.get('composeAutosuggestionSearchText') - let selection = store.get('composeAutosuggestionSelected') || 0 - let account = store.get('composeAutosuggestionSearchResults')[selection] - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { + composeSelectionStart, + composeAutosuggestionSearchText, + composeAutosuggestionSelected, + composeAutosuggestionSearchResults + } = store.get() + composeAutosuggestionSelected = composeAutosuggestionSelected || 0 + let account = composeAutosuggestionSearchResults[composeAutosuggestionSelected] + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart await insertUsername(realm, account.acct, startIndex, endIndex) } @@ -96,8 +98,8 @@ export function setReplyVisibility (realm, replyVisibility) { if (typeof postPrivacy !== 'undefined') { return // user has already set the postPrivacy } - let verifyCredentials = store.get('currentVerifyCredentials') - let defaultVisibility = verifyCredentials.source.privacy + let { currentVerifyCredentials } = store.get() + let defaultVisibility = currentVerifyCredentials.source.privacy let visibility = PRIVACY_LEVEL[replyVisibility] < PRIVACY_LEVEL[defaultVisibility] ? replyVisibility : defaultVisibility diff --git a/routes/_actions/delete.js b/routes/_actions/delete.js index a127b45b..edc6a823 100644 --- a/routes/_actions/delete.js +++ b/routes/_actions/delete.js @@ -3,10 +3,9 @@ import { deleteStatus } from '../_api/delete' import { toast } from '../_utils/toast' export async function doDeleteStatus (statusId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { - await deleteStatus(instanceName, accessToken, statusId) + await deleteStatus(currentInstance, accessToken, statusId) toast.say('Status deleted.') } catch (e) { console.error(e) diff --git a/routes/_actions/emoji.js b/routes/_actions/emoji.js index 62488206..d63a6a2a 100644 --- a/routes/_actions/emoji.js +++ b/routes/_actions/emoji.js @@ -12,7 +12,7 @@ export async function updateCustomEmojiForInstance (instanceName) { () => getCustomEmojiFromDatabase(instanceName), emoji => setCustomEmojiInDatabase(instanceName, emoji), emoji => { - let customEmoji = store.get('customEmoji') + let { customEmoji } = store.get() customEmoji[instanceName] = emoji store.set({customEmoji: customEmoji}) } @@ -20,7 +20,8 @@ export async function updateCustomEmojiForInstance (instanceName) { } export function insertEmoji (realm, emoji) { - let idx = store.get('composeSelectionStart') || 0 + let { composeSelectionStart } = store.get() + let idx = composeSelectionStart || 0 let oldText = store.getComposeData(realm, 'text') || '' let pre = oldText.substring(0, idx) let post = oldText.substring(idx) @@ -37,11 +38,15 @@ export function insertEmojiAtPosition (realm, emoji, startIndex, endIndex) { } export async function clickSelectedAutosuggestionEmoji (realm) { - let selectionStart = store.get('composeSelectionStart') - let searchText = store.get('composeAutosuggestionSearchText') - let selection = store.get('composeAutosuggestionSelected') || 0 - let emoji = store.get('composeAutosuggestionSearchResults')[selection] - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { + composeSelectionStart, + composeAutosuggestionSearchText, + composeAutosuggestionSelected, + composeAutosuggestionSearchResults + } = store.get() + composeAutosuggestionSelected = composeAutosuggestionSelected || 0 + let emoji = composeAutosuggestionSearchResults[composeAutosuggestionSelected] + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart await insertEmojiAtPosition(realm, emoji, startIndex, endIndex) } diff --git a/routes/_actions/favorite.js b/routes/_actions/favorite.js index 15f4eb7d..d667b882 100644 --- a/routes/_actions/favorite.js +++ b/routes/_actions/favorite.js @@ -6,22 +6,22 @@ import { } from '../_database/timelines/updateStatus' export async function setFavorited (statusId, favorited) { - if (!store.get('online')) { + let { online } = store.get() + if (!online) { toast.say(`You cannot ${favorited ? 'favorite' : 'unfavorite'} while offline.`) return } - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() let networkPromise = favorited - ? favoriteStatus(instanceName, accessToken, statusId) - : unfavoriteStatus(instanceName, accessToken, statusId) - store.setStatusFavorited(instanceName, statusId, favorited) // optimistic update + ? favoriteStatus(currentInstance, accessToken, statusId) + : unfavoriteStatus(currentInstance, accessToken, statusId) + store.setStatusFavorited(currentInstance, statusId, favorited) // optimistic update try { await networkPromise - await setStatusFavoritedInDatabase(instanceName, statusId, favorited) + await setStatusFavoritedInDatabase(currentInstance, statusId, favorited) } catch (e) { console.error(e) toast.say(`Failed to ${favorited ? 'favorite' : 'unfavorite'}. ` + (e.message || '')) - store.setStatusFavorited(instanceName, statusId, !favorited) // undo optimistic update + store.setStatusFavorited(currentInstance, statusId, !favorited) // undo optimistic update } } diff --git a/routes/_actions/follow.js b/routes/_actions/follow.js index 95751d5a..ffad433b 100644 --- a/routes/_actions/follow.js +++ b/routes/_actions/follow.js @@ -7,17 +7,16 @@ import { } from '../_database/accountsAndRelationships' export async function setAccountFollowed (accountId, follow, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { let account if (follow) { - account = await followAccount(instanceName, accessToken, accountId) + account = await followAccount(currentInstance, accessToken, accountId) } else { - account = await unfollowAccount(instanceName, accessToken, accountId) + account = await unfollowAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) - let relationship = await getRelationshipFromDatabase(instanceName, accountId) + let relationship = await getRelationshipFromDatabase(currentInstance, accountId) if (toastOnSuccess) { if (follow) { if (account.locked && relationship.requested) { diff --git a/routes/_actions/instances.js b/routes/_actions/instances.js index d1ea0827..377fb77f 100644 --- a/routes/_actions/instances.js +++ b/routes/_actions/instances.js @@ -14,17 +14,18 @@ import { } from '../_database/meta' export function changeTheme (instanceName, newTheme) { - let instanceThemes = store.get('instanceThemes') + let { instanceThemes } = store.get() instanceThemes[instanceName] = newTheme store.set({instanceThemes: instanceThemes}) store.save() - if (instanceName === store.get('currentInstance')) { + let { currentInstance } = store.get() + if (instanceName === currentInstance) { switchToTheme(newTheme) } } export function switchToInstance (instanceName) { - let instanceThemes = store.get('instanceThemes') + let { instanceThemes } = store.get() store.set({ currentInstance: instanceName, searchResults: null, @@ -35,11 +36,13 @@ export function switchToInstance (instanceName) { } export async function logOutOfInstance (instanceName) { - let loggedInInstances = store.get('loggedInInstances') - let instanceThemes = store.get('instanceThemes') - let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') - let composeData = store.get('composeData') - let currentInstance = store.get('currentInstance') + let { + loggedInInstances, + instanceThemes, + loggedInInstancesInOrder, + composeData, + currentInstance + } = store.get() loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1) let newInstance = instanceName === currentInstance ? loggedInInstancesInOrder[0] @@ -64,13 +67,13 @@ export async function logOutOfInstance (instanceName) { } function setStoreVerifyCredentials (instanceName, thisVerifyCredentials) { - let verifyCredentials = store.get('verifyCredentials') + let { verifyCredentials } = store.get() verifyCredentials[instanceName] = thisVerifyCredentials store.set({verifyCredentials: verifyCredentials}) } export async function updateVerifyCredentialsForInstance (instanceName) { - let loggedInInstances = store.get('loggedInInstances') + let { loggedInInstances } = store.get() let accessToken = loggedInInstances[instanceName].access_token await cacheFirstUpdateAfter( () => getVerifyCredentials(instanceName, accessToken), @@ -81,7 +84,8 @@ export async function updateVerifyCredentialsForInstance (instanceName) { } export async function updateVerifyCredentialsForCurrentInstance () { - await updateVerifyCredentialsForInstance(store.get('currentInstance')) + let { currentInstance } = store.get() + await updateVerifyCredentialsForInstance(currentInstance) } export async function updateInstanceInfo (instanceName) { @@ -90,7 +94,7 @@ export async function updateInstanceInfo (instanceName) { () => getInstanceInfoFromDatabase(instanceName), info => setInstanceInfoInDatabase(instanceName, info), info => { - let instanceInfos = store.get('instanceInfos') + let { instanceInfos } = store.get() instanceInfos[instanceName] = info store.set({instanceInfos: instanceInfos}) } diff --git a/routes/_actions/lists.js b/routes/_actions/lists.js index a2429260..df510736 100644 --- a/routes/_actions/lists.js +++ b/routes/_actions/lists.js @@ -7,16 +7,15 @@ import { } from '../_database/meta' export async function updateLists () { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await cacheFirstUpdateAfter( - () => getLists(instanceName, accessToken), - () => getListsFromDatabase(instanceName), - lists => setListsInDatabase(instanceName, lists), + () => getLists(currentInstance, accessToken), + () => getListsFromDatabase(currentInstance), + lists => setListsInDatabase(currentInstance, lists), lists => { - let instanceLists = store.get('instanceLists') - instanceLists[instanceName] = lists + let { instanceLists } = store.get() + instanceLists[currentInstance] = lists store.set({instanceLists: instanceLists}) } ) diff --git a/routes/_actions/media.js b/routes/_actions/media.js index 131f3938..1a3808f7 100644 --- a/routes/_actions/media.js +++ b/routes/_actions/media.js @@ -4,11 +4,10 @@ import { toast } from '../_utils/toast' import { scheduleIdleTask } from '../_utils/scheduleIdleTask' export async function doMediaUpload (realm, file) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() store.set({uploadingMedia: true}) try { - let response = await uploadMedia(instanceName, accessToken, file) + let response = await uploadMedia(currentInstance, accessToken, file) let composeMedia = store.getComposeData(realm, 'media') || [] composeMedia.push({ data: response, diff --git a/routes/_actions/mute.js b/routes/_actions/mute.js index a0bc6e47..ff6571f1 100644 --- a/routes/_actions/mute.js +++ b/routes/_actions/mute.js @@ -4,13 +4,12 @@ import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' export async function setAccountMuted (accountId, mute, toastOnSuccess) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() try { if (mute) { - await muteAccount(instanceName, accessToken, accountId) + await muteAccount(currentInstance, accessToken, accountId) } else { - await unmuteAccount(instanceName, accessToken, accountId) + await unmuteAccount(currentInstance, accessToken, accountId) } await updateProfileAndRelationship(accountId) if (toastOnSuccess) { diff --git a/routes/_actions/pinnedStatuses.js b/routes/_actions/pinnedStatuses.js index 87ac664f..52d37040 100644 --- a/routes/_actions/pinnedStatuses.js +++ b/routes/_actions/pinnedStatuses.js @@ -9,18 +9,17 @@ import { } from '../_api/pinnedStatuses' export async function updatePinnedStatusesForAccount (accountId) { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() await cacheFirstUpdateAfter( - () => getPinnedStatuses(instanceName, accessToken, accountId), - () => getPinnedStatusesFromDatabase(instanceName, accountId), - statuses => insertPinnedStatusesInDatabase(instanceName, accountId, statuses), + () => getPinnedStatuses(currentInstance, accessToken, accountId), + () => getPinnedStatusesFromDatabase(currentInstance, accountId), + statuses => insertPinnedStatusesInDatabase(currentInstance, accountId, statuses), statuses => { - let $pinnedStatuses = store.get('pinnedStatuses') - $pinnedStatuses[instanceName] = $pinnedStatuses[instanceName] || {} - $pinnedStatuses[instanceName][accountId] = statuses - store.set({pinnedStatuses: $pinnedStatuses}) + let { pinnedStatuses } = store.get() + pinnedStatuses[currentInstance] = pinnedStatuses[currentInstance] || {} + pinnedStatuses[currentInstance][accountId] = statuses + store.set({pinnedStatuses: pinnedStatuses}) } ) } diff --git a/routes/_actions/reblog.js b/routes/_actions/reblog.js index 5e91c78e..b583ef84 100644 --- a/routes/_actions/reblog.js +++ b/routes/_actions/reblog.js @@ -4,22 +4,22 @@ import { reblogStatus, unreblogStatus } from '../_api/reblog' import { setStatusReblogged as setStatusRebloggedInDatabase } from '../_database/timelines/updateStatus' export async function setReblogged (statusId, reblogged) { - if (!store.get('online')) { + let online = store.get() + if (!online) { toast.say(`You cannot ${reblogged ? 'boost' : 'unboost'} while offline.`) return } - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') + let { currentInstance, accessToken } = store.get() let networkPromise = reblogged - ? reblogStatus(instanceName, accessToken, statusId) - : unreblogStatus(instanceName, accessToken, statusId) - store.setStatusReblogged(instanceName, statusId, reblogged) // optimistic update + ? reblogStatus(currentInstance, accessToken, statusId) + : unreblogStatus(currentInstance, accessToken, statusId) + store.setStatusReblogged(currentInstance, statusId, reblogged) // optimistic update try { await networkPromise - await setStatusRebloggedInDatabase(instanceName, statusId, reblogged) + await setStatusRebloggedInDatabase(currentInstance, statusId, reblogged) } catch (e) { console.error(e) toast.say(`Failed to ${reblogged ? 'boost' : 'unboost'}. ` + (e.message || '')) - store.setStatusReblogged(instanceName, statusId, !reblogged) // undo optimistic update + store.setStatusReblogged(currentInstance, statusId, !reblogged) // undo optimistic update } } diff --git a/routes/_actions/search.js b/routes/_actions/search.js index 2fb25d8f..55a8f2d2 100644 --- a/routes/_actions/search.js +++ b/routes/_actions/search.js @@ -3,14 +3,12 @@ import { toast } from '../_utils/toast' import { search } from '../_api/search' export async function doSearch () { - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let queryInSearch = store.get('queryInSearch') + let { currentInstance, accessToken, queryInSearch } = store.get() store.set({searchLoading: true}) try { - let results = await search(instanceName, accessToken, queryInSearch) - let currentQueryInSearch = store.get('queryInSearch') // avoid race conditions - if (currentQueryInSearch === queryInSearch) { + let results = await search(currentInstance, accessToken, queryInSearch) + let { queryInSearch: newQueryInSearch } = store.get() // avoid race conditions + if (newQueryInSearch === queryInSearch) { store.set({ searchResultsForQuery: queryInSearch, searchResults: results diff --git a/routes/_actions/timeline.js b/routes/_actions/timeline.js index 28bcdf4b..c2d322c0 100644 --- a/routes/_actions/timeline.js +++ b/routes/_actions/timeline.js @@ -60,14 +60,16 @@ export async function addTimelineItemIds (instanceName, timelineName, newIds, ne async function fetchTimelineItemsAndPossiblyFallBack () { mark('fetchTimelineItemsAndPossiblyFallBack') - let timelineName = store.get('currentTimeline') - let instanceName = store.get('currentInstance') - let accessToken = store.get('accessToken') - let lastTimelineItemId = store.get('lastTimelineItemId') - let online = store.get('online') + let { + currentTimeline, + currentInstance, + accessToken, + lastTimelineItemId, + online + } = store.get() - let { items, stale } = await fetchTimelineItems(instanceName, accessToken, timelineName, lastTimelineItemId, online) - addTimelineItems(instanceName, timelineName, items, stale) + let { items, stale } = await fetchTimelineItems(currentInstance, accessToken, currentTimeline, lastTimelineItemId, online) + addTimelineItems(currentInstance, currentTimeline, items, stale) stop('fetchTimelineItemsAndPossiblyFallBack') } @@ -77,10 +79,11 @@ export async function setupTimeline () { // (i.e. via offline mode), then we need to re-fetch // Also do this if it's a thread, because threads change pretty frequently and // we don't have a good way to update them. - - let timelineItemIds = store.get('timelineItemIds') - let timelineItemIdsAreStale = store.get('timelineItemIdsAreStale') - let currentTimeline = store.get('currentTimeline') + let { + timelineItemIds, + timelineItemIdsAreStale, + currentTimeline + } = store.get() if (!timelineItemIds || timelineItemIdsAreStale || currentTimeline.startsWith('status/')) { @@ -109,9 +112,10 @@ export async function showMoreItemsForTimeline (instanceName, timelineName) { } export async function showMoreItemsForCurrentTimeline () { + let { currentInstance, currentTimeline } = store.get() return showMoreItemsForTimeline( - store.get('currentInstance'), - store.get('currentTimeline') + currentInstance, + currentTimeline ) } diff --git a/routes/_components/AccountsListPage.html b/routes/_components/AccountsListPage.html index 73681a10..73e1f5ad 100644 --- a/routes/_components/AccountsListPage.html +++ b/routes/_components/AccountsListPage.html @@ -34,7 +34,7 @@ export default { async oncreate() { - let accountsFetcher = this.get('accountsFetcher') + let { accountsFetcher } = this.get() try { // TODO: paginate let accounts = await accountsFetcher() diff --git a/routes/_components/IconButton.html b/routes/_components/IconButton.html index 02d4d9fa..fc166951 100644 --- a/routes/_components/IconButton.html +++ b/routes/_components/IconButton.html @@ -107,7 +107,8 @@ export default { oncreate() { this.observe('animation', animation => { - if (!animation || this.store.get('reduceMotion')) { + let reduceMotion = this.store.get() + if (!animation || reduceMotion) { return } let svg = this.refs.svg diff --git a/routes/_components/LazyImage.html b/routes/_components/LazyImage.html index 55b62911..39041357 100644 --- a/routes/_components/LazyImage.html +++ b/routes/_components/LazyImage.html @@ -28,8 +28,8 @@ oncreate() { mark('LazyImage oncreate()') let img = new Image() - let src = this.get('src') - let fallback = this.get('fallback') + let { src } = this.get() + let { fallback } = this.get() img.onload = () => { requestAnimationFrame(() => { this.set({ diff --git a/routes/_components/NavItem.html b/routes/_components/NavItem.html index 9e0848d8..77388a58 100644 --- a/routes/_components/NavItem.html +++ b/routes/_components/NavItem.html @@ -136,7 +136,8 @@ }, methods: { onClick(e) { - if (!this.get('selected')) { + let { selected } = this.get() + if (!selected) { return } e.preventDefault() diff --git a/routes/_components/NonAutoplayImg.html b/routes/_components/NonAutoplayImg.html index b1571634..be8df07d 100644 --- a/routes/_components/NonAutoplayImg.html +++ b/routes/_components/NonAutoplayImg.html @@ -28,11 +28,8 @@ export default { methods: { onMouseOver(mouseOver) { - if (mouseOver) { - this.refs.node.src = this.get('src') - } else { - this.refs.node.src = this.get('staticSrc') - } + let { src, staticSrc } = this.get() + this.refs.node.src = mouseOver ? src : staticSrc } }, events: { diff --git a/routes/_components/community/PageListItem.html b/routes/_components/community/PageListItem.html index 951b6035..4bc8ad7f 100644 --- a/routes/_components/community/PageListItem.html +++ b/routes/_components/community/PageListItem.html @@ -75,9 +75,8 @@ methods: { onPinClick(e) { e.preventDefault() - let currentInstance = this.store.get('currentInstance') - let pinnedPages = this.store.get('pinnedPages') - let href = this.get('href') + let { currentInstance, pinnedPages } = this.store.get() + let { href } = this.get() pinnedPages[currentInstance] = href this.store.set({pinnedPages: pinnedPages}) this.store.save() diff --git a/routes/_components/compose/ComposeAutosuggest.html b/routes/_components/compose/ComposeAutosuggest.html index 8f2ce159..0dc4bf49 100644 --- a/routes/_components/compose/ComposeAutosuggest.html +++ b/routes/_components/compose/ComposeAutosuggest.html @@ -59,13 +59,15 @@ // perf improves for input responsiveness this.observe('composeSelectionStart', () => { scheduleIdleTask(() => { - this.set({composeSelectionStartDeferred: this.get('composeSelectionStart')}) + let { composeSelectionStart } = this.get() || {} // TODO: wtf svelte? + this.set({composeSelectionStartDeferred: composeSelectionStart}) }) }) this.observe('composeFocused', (composeFocused) => { let updateFocusedState = () => { scheduleIdleTask(() => { - this.set({composeFocusedDeferred: this.get('composeFocused')}) + let { composeFocused } = this.get() || {} // TODO: wtf svelte? + this.set({composeFocusedDeferred: composeFocused}) }) } @@ -103,11 +105,10 @@ once: once, onClick(item) { this.fire('autosuggestItemSelected') - let realm = this.get('realm') - let selectionStart = this.store.get('composeSelectionStart') - let searchText = this.store.get('composeAutosuggestionSearchText') - let startIndex = selectionStart - searchText.length - let endIndex = selectionStart + let { realm } = this.get() + let { composeSelectionStart, composeAutosuggestionSearchText } = this.store.get() + let startIndex = composeSelectionStart - composeAutosuggestionSearchText.length + let endIndex = composeSelectionStart if (item.acct) { /* no await */ insertUsername(realm, item.acct, startIndex, endIndex) } else { @@ -117,15 +118,15 @@ }, async searchAccounts(searchText) { searchText = searchText.substring(1) - let currentInstance = this.store.get('currentInstance') + let { currentInstance } = this.store.get() let results = await searchAccountsByUsernameInDatabase( currentInstance, searchText, DATABASE_SEARCH_RESULTS_LIMIT) return results.slice(0, SEARCH_RESULTS_LIMIT) }, searchEmoji(searchText) { searchText = searchText.toLowerCase().substring(1) - let customEmoji = this.store.get('currentCustomEmoji') - let results = customEmoji.filter(emoji => emoji.shortcode.toLowerCase().startsWith(searchText)) + let { currentCustomEmoji } = this.store.get() + let results = currentCustomEmoji.filter(emoji => emoji.shortcode.toLowerCase().startsWith(searchText)) .sort((a, b) => a.shortcode.toLowerCase() < b.shortcode.toLowerCase() ? -1 : 1) .slice(0, SEARCH_RESULTS_LIMIT) return results diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index 740151ad..bde904df 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -118,7 +118,7 @@ export default { oncreate() { - let realm = this.get('realm') + let { realm } = this.get() if (realm === 'home') { this.setupStickyObserver() } else if (realm !== 'dialog') { @@ -126,13 +126,13 @@ insertHandleForReply(realm) } - let replySpoiler = this.get('replySpoiler') + let { replySpoiler } = this.get() if (replySpoiler) { // default spoiler is same as the replied-to status setReplySpoiler(realm, replySpoiler) } - let replyVisibility = this.get('replyVisibility') + let { replyVisibility } = this.get() if (replyVisibility) { // make sure the visibility is consistent with the replied-to status setReplyVisibility(realm, replyVisibility) @@ -189,7 +189,8 @@ }, methods: { async onClickPostButton() { - if (this.get('sticky')) { + let { sticky } = this.get() + if (sticky) { // when the button is sticky, we're scrolled down the home timeline, // so we should launch a new compose dialog let dialogs = await importDialogs() @@ -200,17 +201,19 @@ } }, doPostStatus() { - let text = this.get('text') - let media = this.get('media') - let postPrivacyKey = this.get('postPrivacyKey') - let contentWarning = this.get('contentWarning') + let { + text, + media, + postPrivacyKey, + contentWarning, + realm, + overLimit, + mediaDescriptions, + inReplyToUuid + } = this.get() let sensitive = media.length && !!contentWarning - let realm = this.get('realm') let mediaIds = media.map(_ => _.data.id) let inReplyTo = (realm === 'home' || realm === 'dialog') ? null : realm - let overLimit = this.get('overLimit') - let mediaDescriptions = this.get('mediaDescriptions') - let inReplyToUuid = this.get('inReplyToUuid') if (!text || overLimit) { return // do nothing if invalid diff --git a/routes/_components/compose/ComposeContentWarning.html b/routes/_components/compose/ComposeContentWarning.html index a1b112a6..e2a30f69 100644 --- a/routes/_components/compose/ComposeContentWarning.html +++ b/routes/_components/compose/ComposeContentWarning.html @@ -37,7 +37,8 @@ const saveText = debounce(() => scheduleIdleTask(() => this.store.save()), 1000) this.observe('rawText', rawText => { - this.store.setComposeData(this.get('realm'), { + let { realm } = this.get() + this.store.setComposeData(realm, { contentWarning: rawText }) saveText() diff --git a/routes/_components/compose/ComposeInput.html b/routes/_components/compose/ComposeInput.html index d27b406d..9df08596 100644 --- a/routes/_components/compose/ComposeInput.html +++ b/routes/_components/compose/ComposeInput.html @@ -50,7 +50,8 @@ let textarea = this.refs.textarea let firstTime = true this.observe('text', text => { - if (this.get('rawText') !== text) { + let { rawText } = this.get() + if (rawText !== text) { this.set({rawText: text}) // this next autosize is required to resize after // the user clicks the "toot" button @@ -60,7 +61,8 @@ } if (firstTime) { firstTime = false - if (this.get('autoFocus')) { + let { autoFocus } = this.get() + if (autoFocus) { requestAnimationFrame(() => textarea.focus()) } } @@ -71,7 +73,7 @@ this.observe('rawText', rawText => { mark('observe rawText') - let realm = this.get('realm') + let { realm } = this.get() this.store.setComposeData(realm, {text: rawText}) saveStore() stop('observe rawText') @@ -126,27 +128,34 @@ } }, clickSelectedAutosuggestion(event) { - let autosuggestionShown = this.store.get('composeAutosuggestionShown') - if (!autosuggestionShown) { + let { + composeAutosuggestionShown, + composeAutosuggestionType + } = this.store.get() + if (!composeAutosuggestionShown) { return false } - let type = this.store.get('composeAutosuggestionType') - if (type === 'account') { - /* no await */ clickSelectedAutosuggestionUsername(this.get('realm')) + let { realm } = this.get() + if (composeAutosuggestionType === 'account') { + /* no await */ clickSelectedAutosuggestionUsername(realm) } else { // emoji - /* no await */ clickSelectedAutosuggestionEmoji(this.get('realm')) + /* no await */ clickSelectedAutosuggestionEmoji(realm) } event.preventDefault() event.stopPropagation() return true }, incrementAutosuggestSelected(increment, event) { - let autosuggestionShown = this.store.get('composeAutosuggestionShown') - if (!autosuggestionShown) { + let { + composeAutosuggestionShown, + composeAutosuggestionSelected, + composeAutosuggestionSearchResults + } = this.store.get() + if (!composeAutosuggestionShown) { return } - let selected = this.store.get('composeAutosuggestionSelected') || 0 - let searchResults = this.store.get('composeAutosuggestionSearchResults') || [] + let selected = composeAutosuggestionSelected || 0 + let searchResults = composeAutosuggestionSearchResults || [] selected += increment if (selected >= 0) { selected = selected % searchResults.length @@ -158,8 +167,8 @@ event.stopPropagation() }, clearAutosuggestions(event) { - let autosuggestionShown = this.store.get('composeAutosuggestionShown') - if (!autosuggestionShown) { + let { composeAutosuggestionShown } = this.store.get() + if (!composeAutosuggestionShown) { return } this.store.set({ diff --git a/routes/_components/compose/ComposeLengthGauge.html b/routes/_components/compose/ComposeLengthGauge.html index f1dfe3a6..8d8b8636 100644 --- a/routes/_components/compose/ComposeLengthGauge.html +++ b/routes/_components/compose/ComposeLengthGauge.html @@ -25,12 +25,14 @@ export default { oncreate() { - this.set({lengthAsFractionDeferred: this.get('lengthAsFraction')}) + let { lengthAsFraction } = this.get() + this.set({lengthAsFractionDeferred: lengthAsFraction}) // perf improvement for keyboard input latency this.observe('lengthAsFraction', () => { scheduleIdleTask(() => { mark('set lengthAsFractionDeferred') - this.set({lengthAsFractionDeferred: this.get('lengthAsFraction')}) + let { lengthAsFraction } = this.get() || {} // TODO: wtf svelte? + this.set({lengthAsFractionDeferred: lengthAsFraction}) stop('set lengthAsFractionDeferred') requestAnimationFrame(() => this.set({shouldAnimate: true})) }) diff --git a/routes/_components/compose/ComposeLengthIndicator.html b/routes/_components/compose/ComposeLengthIndicator.html index ce01deff..dba68183 100644 --- a/routes/_components/compose/ComposeLengthIndicator.html +++ b/routes/_components/compose/ComposeLengthIndicator.html @@ -23,12 +23,14 @@ export default { oncreate() { - this.set({lengthToDisplayDeferred: this.get('lengthToDisplay')}) + let { lengthToDisplay } = this.get() + this.set({lengthToDisplayDeferred: lengthToDisplay}) // perf improvement for keyboard input latency this.observe('lengthToDisplay', () => { scheduleIdleTask(() => { mark('set lengthToDisplayDeferred') - this.set({lengthToDisplayDeferred: this.get('lengthToDisplay')}) + let { lengthToDisplay } = this.get() || {} // TODO: wtf svelte? + this.set({lengthToDisplayDeferred: lengthToDisplay}) stop('set lengthToDisplayDeferred') }) }, {init: false}) diff --git a/routes/_components/compose/ComposeMediaItem.html b/routes/_components/compose/ComposeMediaItem.html index c56caead..37a32a2f 100644 --- a/routes/_components/compose/ComposeMediaItem.html +++ b/routes/_components/compose/ComposeMediaItem.html @@ -93,9 +93,9 @@ setupSyncFromStore() { this.observe('mediaDescriptions', mediaDescriptions => { mediaDescriptions = mediaDescriptions || [] - let index = this.get('index') + let { index, rawText } = this.get() let text = mediaDescriptions[index] || '' - if (this.get('rawText') !== text) { + if (rawText !== text) { this.set({rawText: text}) } }) @@ -104,8 +104,8 @@ const saveStore = debounce(() => scheduleIdleTask(() => this.store.save()), 1000) this.observe('rawText', rawText => { - let realm = this.get('realm') - let index = this.get('index') + let { realm } = this.get() + let { index } = this.get() let mediaDescriptions = store.getComposeData(realm, 'mediaDescriptions') || [] if (mediaDescriptions[index] === rawText) { return @@ -119,7 +119,11 @@ }, {init: false}) }, onDeleteMedia() { - deleteMedia(this.get('realm'), this.get('index')) + let { + realm, + index + } = this.get() + deleteMedia(realm, index) } } } diff --git a/routes/_components/compose/ComposeToolbar.html b/routes/_components/compose/ComposeToolbar.html index 62a858ab..2059a4c6 100644 --- a/routes/_components/compose/ComposeToolbar.html +++ b/routes/_components/compose/ComposeToolbar.html @@ -71,22 +71,25 @@ methods: { async onEmojiClick() { let dialogs = await importDialogs() - dialogs.showEmojiDialog(this.get('realm')) + let { realm } = this.get() + dialogs.showEmojiDialog(realm) }, onMediaClick() { this.refs.input.click() }, onFileChange(e) { let file = e.target.files[0] - let realm = this.get('realm') + let { realm } = this.get() doMediaUpload(realm, file) }, async onPostPrivacyClick() { let dialogs = await importDialogs() - dialogs.showPostPrivacyDialog(this.get('realm')) + let { realm } = this.get() + dialogs.showPostPrivacyDialog(realm) }, onContentWarningClick() { - toggleContentWarningShown(this.get('realm')) + let { realm } = this.get() + toggleContentWarningShown(realm) } } } diff --git a/routes/_components/dialog/components/AccountProfileOptionsDialog.html b/routes/_components/dialog/components/AccountProfileOptionsDialog.html index 9a187b28..a0d3fdb4 100644 --- a/routes/_components/dialog/components/AccountProfileOptionsDialog.html +++ b/routes/_components/dialog/components/AccountProfileOptionsDialog.html @@ -99,7 +99,7 @@ export default { } }, async onMentionClicked() { - let acct = this.get('acct') + let { acct } = this.get() this.store.setComposeData('dialog', { text: `@${acct} ` }) @@ -108,21 +108,17 @@ export default { this.close() }, async onFollowClicked() { - let accountId = this.get('accountId') - let following = this.get('following') + let { accountId, following } = this.get() this.close() await setAccountFollowed(accountId, !following, true) }, async onBlockClicked() { - let account = this.get('account') - let blocking = this.get('blocking') - let accountId = account.id + let { accountId, blocking } = this.get() this.close() await setAccountBlocked(accountId, !blocking, true) }, async onMuteClicked() { - let accountId = this.get('accountId') - let muting = this.get('muting') + let { accountId, muting } = this.get() this.close() await setAccountMuted(accountId, !muting, true) } diff --git a/routes/_components/dialog/components/ConfirmationDialog.html b/routes/_components/dialog/components/ConfirmationDialog.html index f6788783..8047fa20 100644 --- a/routes/_components/dialog/components/ConfirmationDialog.html +++ b/routes/_components/dialog/components/ConfirmationDialog.html @@ -47,17 +47,23 @@ methods: { show, close, - onDestroyDialog(id) { - if (id !== this.get('id')) { + onDestroyDialog(thisId) { + let { + id, + positiveResult, + onPositive, + onNegative + } = this.get() + if (thisId !== id) { return } - if (this.get('positiveResult')) { - if (this.get('onPositive')) { - this.get('onPositive')() + if (positiveResult) { + if (onPositive) { + onPositive() } } else { - if (this.get('onNegative')) { - this.get('onNegative')() + if (onNegative) { + onNegative() } } }, diff --git a/routes/_components/dialog/components/EmojiDialog.html b/routes/_components/dialog/components/EmojiDialog.html index e90ef484..4ed61e4f 100644 --- a/routes/_components/dialog/components/EmojiDialog.html +++ b/routes/_components/dialog/components/EmojiDialog.html @@ -82,7 +82,8 @@ show, close, onClickEmoji(emoji) { - insertEmoji(this.get('realm'), emoji) + let { realm } = this.get() + insertEmoji(realm, emoji) this.close() } } diff --git a/routes/_components/dialog/components/ModalDialog.html b/routes/_components/dialog/components/ModalDialog.html index 71d48a50..776a99f2 100644 --- a/routes/_components/dialog/components/ModalDialog.html +++ b/routes/_components/dialog/components/ModalDialog.html @@ -132,7 +132,8 @@ this._a11yDialog = new A11yDialog(dialogElement) this._a11yDialog.on('hide', () => { this._a11yDialog.destroy() - emit('destroyDialog', this.get('id')) + let { id } = this.get() + emit('destroyDialog', id) requestAnimationFrame(() => document.body.removeChild(dialogElement)) }) on('showDialog', this, this.showDialog) @@ -161,8 +162,9 @@ } }, methods: { - showDialog(id) { - if (this.get('id') !== id) { + showDialog(thisId) { + let { id } = this.get() + if (id !== thisId) { return } this._a11yDialog.show() @@ -170,8 +172,9 @@ this.set({ fadedIn: true }) }) }, - closeDialog(id) { - if (this.get('id') !== id) { + closeDialog(thisId) { + let { id } = this.get() + if (id !== thisId) { return } setTimeout(() => { // use setTimeout to workaround svelte timing issue diff --git a/routes/_components/dialog/components/PostPrivacyDialog.html b/routes/_components/dialog/components/PostPrivacyDialog.html index 7c7f724e..2d6a4be2 100644 --- a/routes/_components/dialog/components/PostPrivacyDialog.html +++ b/routes/_components/dialog/components/PostPrivacyDialog.html @@ -30,7 +30,8 @@ show, close, onClick(item) { - setPostPrivacy(this.get('realm'), item.key) + let { realm } = this.get() + setPostPrivacy(realm, item.key) this.close() } }, diff --git a/routes/_components/dialog/components/StatusOptionsDialog.html b/routes/_components/dialog/components/StatusOptionsDialog.html index d5445906..6457216b 100644 --- a/routes/_components/dialog/components/StatusOptionsDialog.html +++ b/routes/_components/dialog/components/StatusOptionsDialog.html @@ -102,25 +102,22 @@ export default { } }, async onDeleteClicked() { - let statusId = this.get('statusId') + let { statusId } = this.get() this.close() await doDeleteStatus(statusId) }, async onFollowClicked() { - let accountId = this.get('accountId') - let following = this.get('following') + let { accountId, following } = this.get() this.close() await setAccountFollowed(accountId, !following, true) }, async onBlockClicked() { - let accountId = this.get('accountId') - let blocking = this.get('blocking') + let { accountId, blocking } = this.get() this.close() await setAccountBlocked(accountId, !blocking, true) }, async onMuteClicked() { - let accountId = this.get('accountId') - let muting = this.get('muting') + let { accountId, muting } = this.get() this.close() await setAccountMuted(accountId, !muting, true) } diff --git a/routes/_components/dialog/helpers/closeDialog.js b/routes/_components/dialog/helpers/closeDialog.js index 351d1c09..669d8243 100644 --- a/routes/_components/dialog/helpers/closeDialog.js +++ b/routes/_components/dialog/helpers/closeDialog.js @@ -1,6 +1,6 @@ import { emit } from '../../../_utils/eventBus' export function close () { - let id = this.get('id') + let { id } = this.get() emit('closeDialog', id) } diff --git a/routes/_components/dialog/helpers/onCreateDialog.js b/routes/_components/dialog/helpers/onCreateDialog.js index 6a04a06f..42b0c859 100644 --- a/routes/_components/dialog/helpers/onCreateDialog.js +++ b/routes/_components/dialog/helpers/onCreateDialog.js @@ -1,7 +1,8 @@ import { on } from '../../../_utils/eventBus' -function onDestroy (id) { - if (this.get('id') !== id) { +function onDestroy (thisId) { + let { id } = this.get() + if (id !== thisId) { return } this.destroy() diff --git a/routes/_components/dialog/helpers/showDialog.js b/routes/_components/dialog/helpers/showDialog.js index 651a7853..2b0e501c 100644 --- a/routes/_components/dialog/helpers/showDialog.js +++ b/routes/_components/dialog/helpers/showDialog.js @@ -1,6 +1,6 @@ import { emit } from '../../../_utils/eventBus' export function show () { - let id = this.get('id') + let { id } = this.get() emit('showDialog', id) } diff --git a/routes/_components/profile/AccountProfileDetails.html b/routes/_components/profile/AccountProfileDetails.html index 1072c94f..446e8e18 100644 --- a/routes/_components/profile/AccountProfileDetails.html +++ b/routes/_components/profile/AccountProfileDetails.html @@ -121,9 +121,7 @@ }, methods: { async onMoreOptionsClick() { - let account = this.get('account') - let relationship = this.get('relationship') - let verifyCredentials = this.get('verifyCredentials') + let { account, relationship, verifyCredentials } = this.get() let dialogs = await importDialogs() dialogs.showAccountProfileOptionsDialog(account, relationship, verifyCredentials) } diff --git a/routes/_components/profile/AccountProfileFollow.html b/routes/_components/profile/AccountProfileFollow.html index 9e663041..93947cbc 100644 --- a/routes/_components/profile/AccountProfileFollow.html +++ b/routes/_components/profile/AccountProfileFollow.html @@ -31,11 +31,13 @@ async onFollowButtonClick(e) { e.preventDefault() e.stopPropagation() - let account = this.get('account') - let accountId = this.get('accountId') - let following = this.get('following') - let followRequested = this.get('followRequested') - let blocking = this.get('blocking') + let { + account, + accountId, + following, + followRequested, + blocking + } = this.get() this.set({animateFollowButton: true}) // TODO: this should be an event, not toggling a boolean if (blocking) { // unblock await setAccountBlocked(accountId, false) diff --git a/routes/_components/pseudoVirtualList/PseudoVirtualList.html b/routes/_components/pseudoVirtualList/PseudoVirtualList.html index 5d33bf1f..1018d255 100644 --- a/routes/_components/pseudoVirtualList/PseudoVirtualList.html +++ b/routes/_components/pseudoVirtualList/PseudoVirtualList.html @@ -28,25 +28,28 @@ export default { oncreate() { mark('PseudoVirtualList oncreate()') - this.store.setCurrentRealm(this.get('realm')) + let { realm } = this.get() + this.store.setCurrentRealm(realm) // When re-rendering, assume all items are non-intersecting until told otherwise. // We already have the heights cached. - let intersectionStates = this.store.get('intersectionStates') + let { intersectionStates } = this.store.get() let keys = Object.keys(intersectionStates) for (let key of keys) { intersectionStates[key].isCached = true } this.store.setForRealm({intersectionStates: intersectionStates}) + let { containerQuery } = this.get() let intersectionObserver = new IntersectionObserver(this.onIntersection.bind(this), { - root: document.querySelector(this.get('containerQuery')), + root: document.querySelector(containerQuery), rootMargin: '300% 0px' }) this.set({intersectionObserver}) this.observe('allItemsHaveHeight', allItemsHaveHeight => { console.log('allItemsHaveHeight', allItemsHaveHeight) - if (allItemsHaveHeight && !this.get('initialized')) { + let { initialized } = this.get() + if (allItemsHaveHeight && !initialized) { this.set({initialized: true}) console.log('initialized PseudoVirtualList') this.fire('initialized') @@ -55,7 +58,7 @@ stop('PseudoVirtualList oncreate()') }, ondestroy() { - let intersectionObserver = this.get('intersectionObserver') + let { intersectionObserver } = this.get() if (intersectionObserver) { intersectionObserver.disconnect() } @@ -74,7 +77,8 @@ }, methods: { scrollToPosition(element) { - if (this.get('scrolledToPosition')) { + let { scrolledToPosition } = this.get() + if (scrolledToPosition) { return } this.set({scrolledToPosition: true}) @@ -86,8 +90,8 @@ onIntersection(entries) { mark('onIntersection') let newIntersectionStates = {} - let scrollToItem = this.get('scrollToItem') - let intersectionStates = this.store.get('intersectionStates') + let { scrollToItem } = this.get() + let { intersectionStates } = this.store.get() for (let entry of entries) { let key = entry.target.getAttribute('pseudo-virtual-list-key') let rect = getRectFromEntry(entry) diff --git a/routes/_components/pseudoVirtualList/PseudoVirtualListItem.html b/routes/_components/pseudoVirtualList/PseudoVirtualListItem.html index a85eff9d..cee0aa45 100644 --- a/routes/_components/pseudoVirtualList/PseudoVirtualListItem.html +++ b/routes/_components/pseudoVirtualList/PseudoVirtualListItem.html @@ -12,7 +12,6 @@ {{/if}}