From cdc7f3e71a979a15575ff10e09673b4ae514c7f4 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 30 Jul 2023 14:07:01 +0200 Subject: [PATCH] client: Use method definition syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions > Method definition is a shorter syntax for defining a function property in an object initializer. It will make the diffs smaller when we migrate to classes. --- client/js/selfoss-base.js | 34 ++++++++++++++++----------------- client/js/selfoss-db-offline.js | 34 ++++++++++++++++----------------- client/js/selfoss-db-online.js | 8 ++++---- client/js/selfoss-db.js | 14 +++++++------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/client/js/selfoss-base.js b/client/js/selfoss-base.js index aef6e1d6b9..32dfa431c5 100644 --- a/client/js/selfoss-base.js +++ b/client/js/selfoss-base.js @@ -36,7 +36,7 @@ const selfoss = { /** * initialize application */ - init: async function() { + async init() { // Load off-line mode enabledness. selfoss.db.enableOffline.update(window.localStorage.getItem('enableOffline') === 'true'); @@ -75,7 +75,7 @@ const selfoss = { }, - initMain: async function(configuration) { + async initMain(configuration) { selfoss.config = configuration; if (selfoss.db.enableOffline.value) { @@ -120,7 +120,7 @@ const selfoss = { /** * Create basic DOM structure of the page. */ - attachApp: function(configuration) { + attachApp(configuration) { document.getElementById('js-loading-message')?.remove(); const mainUi = document.createElement('div'); @@ -145,19 +145,19 @@ const selfoss = { loggedin: new ValueListenable(false), - setSession: function() { + setSession() { window.localStorage.setItem('onlineSession', true); selfoss.loggedin.update(true); }, - clearSession: function() { + clearSession() { window.localStorage.removeItem('onlineSession'); selfoss.loggedin.update(false); }, - hasSession: function() { + hasSession() { return selfoss.loggedin.value; }, @@ -165,7 +165,7 @@ const selfoss = { * Try to log in using given credentials * @return Promise */ - login: function({ configuration, username, password, enableOffline }) { + login({ configuration, username, password, enableOffline }) { selfoss.db.enableOffline.update(enableOffline); window.localStorage.setItem('enableOffline', selfoss.db.enableOffline.value); if (!selfoss.db.enableOffline.value) { @@ -198,7 +198,7 @@ const selfoss = { }); }, - setupServiceWorker: function() { + setupServiceWorker() { if (!('serviceWorker' in navigator) || selfoss.serviceWorkerInitialized) { return; } @@ -224,7 +224,7 @@ const selfoss = { }); }, - logout: async function() { + async logout() { selfoss.clearSession(); selfoss.db.clear(); // will not work after a failure, since storage is nulled @@ -295,7 +295,7 @@ const selfoss = { * * @return true if device resolution smaller equals 1024 */ - isMobile: function() { + isMobile() { // first check useragent if ((/iPhone|iPod|iPad|Android|BlackBerry/).test(navigator.userAgent)) { return true; @@ -311,7 +311,7 @@ const selfoss = { * * @return true if device resolution smaller equals 1024 */ - isTablet: function() { + isTablet() { if (document.body.clientWidth <= 1024) { return true; } @@ -324,7 +324,7 @@ const selfoss = { * * @return true if device resolution smaller equals 1024 */ - isSmartphone: function() { + isSmartphone() { if (document.body.clientWidth <= 640) { return true; } @@ -351,7 +351,7 @@ const selfoss = { * @param {Number} new unread stats * @param {Number} new starred stats */ - refreshStats: function(all, unread, starred) { + refreshStats(all, unread, starred) { selfoss.app.setAllItemsCount(all); selfoss.app.setStarredItemsCount(starred); @@ -365,7 +365,7 @@ const selfoss = { * @return void * @param {Number} new unread stats */ - refreshUnread: function(unread) { + refreshUnread(unread) { selfoss.app.setUnreadItemsCount(unread); }, @@ -375,7 +375,7 @@ const selfoss = { * * @return void */ - reloadTags: function() { + reloadTags() { selfoss.app.setTagsState(LoadingState.LOADING); getAllTags().then((data) => { @@ -388,7 +388,7 @@ const selfoss = { }, - handleAjaxError: function(error, tryOffline = true) { + handleAjaxError(error, tryOffline = true) { if (!(error instanceof HttpError || error instanceof TimeoutError)) { return Promise.reject(error); } @@ -403,7 +403,7 @@ const selfoss = { }, - listenWaitingSW: function(reg, callback) { + listenWaitingSW(reg, callback) { const awaitStateChange = () => { reg.installing.addEventListener('statechange', (event) => { if (event.target.state === 'installed') { diff --git a/client/js/selfoss-db-offline.js b/client/js/selfoss-db-offline.js index a1502a8dba..9b89efd8e6 100644 --- a/client/js/selfoss-db-offline.js +++ b/client/js/selfoss-db-offline.js @@ -16,7 +16,7 @@ selfoss.dbOffline = { shouldLoadEntriesOnline: false, olderEntriesOnline: false, - _tr: function(...args) { + _tr(...args) { return selfoss.db.storage.transaction(...args) .catch((error) => { selfoss.app.showError( @@ -37,7 +37,7 @@ selfoss.dbOffline = { }, - init: function() { + init() { if (!selfoss.db.enableOffline.value || selfoss.db.storage) { return; } @@ -129,7 +129,7 @@ selfoss.dbOffline = { }, - _memLastItemId: function() { + _memLastItemId() { return selfoss.db.storage.entries.orderBy('id').reverse().first((entry) => { if (entry) { selfoss.dbOffline.lastItemId = entry.id; @@ -140,7 +140,7 @@ selfoss.dbOffline = { }, - storeEntries: function(entries) { + storeEntries(entries) { return selfoss.dbOffline._tr( 'rw', selfoss.db.storage.entries, @@ -158,7 +158,7 @@ selfoss.dbOffline = { }, - GCEntries: function(more = false) { + GCEntries(more = false) { if (more) { // We need to garbage collect more, as the browser storage limit // seems to be exceeded: decrease the amount of days entries are @@ -211,7 +211,7 @@ selfoss.dbOffline = { }, - storeStats: function(stats) { + storeStats(stats) { return selfoss.dbOffline._tr('rw', selfoss.db.storage.stats, () => { for (const [name, value] of Object.entries(stats)) { selfoss.db.storage.stats.put({ @@ -223,7 +223,7 @@ selfoss.dbOffline = { }, - storeLastUpdate: function(lastUpdate) { + storeLastUpdate(lastUpdate) { return selfoss.dbOffline._tr('rw', selfoss.db.storage.stamps, () => { if (lastUpdate) { selfoss.db.storage.stamps.put({ @@ -235,7 +235,7 @@ selfoss.dbOffline = { }, - getEntries: function(fetchParams) { + getEntries(fetchParams) { let hasMore = false; return selfoss.dbOffline._tr( 'r', @@ -310,7 +310,7 @@ selfoss.dbOffline = { }, - reloadOnlineStats: function() { + reloadOnlineStats() { return selfoss.dbOffline._tr( 'r', selfoss.db.storage.stats, @@ -328,7 +328,7 @@ selfoss.dbOffline = { }, - refreshStats: function() { + refreshStats() { return selfoss.dbOffline._tr( 'r', selfoss.db.storage.entries, @@ -353,7 +353,7 @@ selfoss.dbOffline = { }, - enqueueStatuses: function(statuses) { + enqueueStatuses(statuses) { if (statuses) { selfoss.dbOffline.needsSync = true; } @@ -376,7 +376,7 @@ selfoss.dbOffline = { }, - enqueueStatus: function(entryId, statusName, statusValue) { + enqueueStatus(entryId, statusName, statusValue) { return selfoss.dbOffline.enqueueStatuses([{ entryId: entryId, name: statusName, @@ -385,7 +385,7 @@ selfoss.dbOffline = { }, - sendNewStatuses: function() { + sendNewStatuses() { selfoss.db.storage.statusq.toArray().then(statuses => { return statuses.map(s => { const statusUpdate = { @@ -407,7 +407,7 @@ selfoss.dbOffline = { }, - storeEntryStatuses: function(itemStatuses, dequeue = false, updateStats = true) { + storeEntryStatuses(itemStatuses, dequeue = false, updateStats = true) { return selfoss.dbOffline._tr( 'rw', selfoss.db.storage.entries, @@ -470,7 +470,7 @@ selfoss.dbOffline = { }, - entriesMark: function(itemIds, unread) { + entriesMark(itemIds, unread) { selfoss.dbOnline.statsDirty = true; const newStatuses = itemIds.map((itemId) => { return {id: itemId, unread: unread}; @@ -479,12 +479,12 @@ selfoss.dbOffline = { }, - entryMark: function(itemId, unread) { + entryMark(itemId, unread) { return selfoss.dbOffline.entriesMark([itemId], unread); }, - entryStar: function(itemId, starred) { + entryStar(itemId, starred) { return selfoss.dbOffline.storeEntryStatuses([{ id: itemId, starred: starred diff --git a/client/js/selfoss-db-online.js b/client/js/selfoss-db-online.js index ebfd84b5b8..1aad022eba 100644 --- a/client/js/selfoss-db-online.js +++ b/client/js/selfoss-db-online.js @@ -16,7 +16,7 @@ selfoss.dbOnline = { firstSync: true, - _syncBegin: function() { + _syncBegin() { if (!selfoss.dbOnline.syncing.promise) { selfoss.dbOnline.syncing.promise = new Promise((resolve, reject) => { selfoss.dbOnline.syncing.resolve = resolve; @@ -52,7 +52,7 @@ selfoss.dbOnline = { }, - _syncDone: function(success = true) { + _syncDone(success = true) { if (selfoss.dbOnline.syncing.promise) { if (success) { selfoss.dbOnline.syncing.resolve(); @@ -72,7 +72,7 @@ selfoss.dbOnline = { * * @return Promise */ - sync: function(updatedStatuses, chained) { + sync(updatedStatuses, chained) { if (selfoss.dbOnline.syncing.promise && !chained) { if (updatedStatuses) { // Ensure the status queue is not cleared and gets sync'ed at @@ -230,7 +230,7 @@ selfoss.dbOnline = { * * @return void */ - getEntries: function(fetchParams, abortController) { + getEntries(fetchParams, abortController) { return itemsRequests.getItems({ ...fetchParams, itemsPerPage: selfoss.config.itemsPerPage diff --git a/client/js/selfoss-db.js b/client/js/selfoss-db.js index bc3be53d60..ead843825d 100644 --- a/client/js/selfoss-db.js +++ b/client/js/selfoss-db.js @@ -30,7 +30,7 @@ selfoss.db = { lastUpdate: null, - setOnline: function() { + setOnline() { if (!selfoss.db.online) { selfoss.db.online = true; selfoss.db.sync(); @@ -40,12 +40,12 @@ selfoss.db = { }, - tryOnline: function() { + tryOnline() { return selfoss.db.sync(true); }, - setOffline: function() { + setOffline() { if (selfoss.db.storage && !selfoss.db.broken) { selfoss.dbOnline._syncDone(false); selfoss.db.online = false; @@ -59,7 +59,7 @@ selfoss.db = { }, - clear: function() { + clear() { if (selfoss.db.storage) { window.localStorage.removeItem('offlineDays'); const clearing = selfoss.db.storage.delete(); @@ -72,12 +72,12 @@ selfoss.db = { }, - isValidTag: function(name) { + isValidTag(name) { return selfoss.app.state.tags.length === 0 || selfoss.app.state.tags.find((tag) => tag.tag === name) !== undefined; }, - isValidSource: function(id) { + isValidSource(id) { return selfoss.app.state.sources.length === 0 || selfoss.app.state.sources.find((source) => source.id === id) !== undefined; }, @@ -85,7 +85,7 @@ selfoss.db = { lastSync: null, - sync: function(force = false) { + sync(force = false) { const lastUpdateIsOld = selfoss.db.lastUpdate === null || selfoss.db.lastSync === null || Date.now() - selfoss.db.lastSync > 5 * 60 * 1000; const shouldSync = force || selfoss.dbOffline.needsSync || lastUpdateIsOld; if (selfoss.isAllowedToRead() && selfoss.isOnline() && shouldSync) {