From ef8dbb9074a2f090f3f438ff897e61e884e52d65 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 1 Aug 2022 17:53:07 +0530 Subject: [PATCH] Small improvements to code. --- src/components/FeedPage.vue | 7 +------ src/main.js | 7 ++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue index 404a986c..ea69ad0f 100644 --- a/src/components/FeedPage.vue +++ b/src/components/FeedPage.vue @@ -87,12 +87,7 @@ export default { }, getUnauthenticatedChannels() { const localSubscriptions = this.getLocalSubscriptions(); - var channels = ""; - localSubscriptions.forEach((element, index) => { - channels += element; - if (localSubscriptions.size != index) channels += ","; - }); - return channels; + return localSubscriptions.join(","); }, }, }; diff --git a/src/main.js b/src/main.js index f8ef6287..685d1cbe 100644 --- a/src/main.js +++ b/src/main.js @@ -208,11 +208,12 @@ const mixin = { return localSubscriptions.includes(channelId); }, handleLocalSubscriptions(channelId) { - var localSubscriptions = this.getLocalSubscriptions(); - if (localSubscriptions == null || localSubscriptions.size == 0) localSubscriptions = [channelId]; - else if (localSubscriptions.includes(channelId)) + var localSubscriptions = this.getLocalSubscriptions() ?? []; + if (localSubscriptions.includes(channelId)) localSubscriptions.splice(localSubscriptions.indexOf(channelId)); else localSubscriptions.push(channelId); + // Sort for better cache hits + localSubscriptions.sort(); localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions)); }, },