Skip to content

Commit

Permalink
Create empty subscriptions cache objects directly instead of cloning (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Mar 27, 2024
1 parent b1244b7 commit 598d970
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/renderer/store/modules/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { deepCopy } from '../../helpers/utils'

const defaultCacheEntryValueForForOneChannel = {
videos: null,
}

const state = {
videoCache: {},
liveCache: {},
Expand Down Expand Up @@ -77,7 +71,7 @@ const actions = {
const mutations = {
updateVideoCacheByChannel(state, { channelId, videos }) {
const existingObject = state.videoCache[channelId]
const newObject = existingObject != null ? existingObject : deepCopy(defaultCacheEntryValueForForOneChannel)
const newObject = existingObject ?? { videos: null }
if (videos != null) { newObject.videos = videos }
state.videoCache[channelId] = newObject
},
Expand All @@ -86,7 +80,7 @@ const mutations = {
},
updateShortsCacheByChannel(state, { channelId, videos }) {
const existingObject = state.shortsCache[channelId]
const newObject = existingObject != null ? existingObject : deepCopy(defaultCacheEntryValueForForOneChannel)
const newObject = existingObject ?? { videos: null }
if (videos != null) { newObject.videos = videos }
state.shortsCache[channelId] = newObject
},
Expand Down Expand Up @@ -120,7 +114,7 @@ const mutations = {
},
updateLiveCacheByChannel(state, { channelId, videos }) {
const existingObject = state.liveCache[channelId]
const newObject = existingObject != null ? existingObject : deepCopy(defaultCacheEntryValueForForOneChannel)
const newObject = existingObject ?? { videos: null }
if (videos != null) { newObject.videos = videos }
state.liveCache[channelId] = newObject
},
Expand All @@ -129,7 +123,7 @@ const mutations = {
},
updatePostsCacheByChannel(state, { channelId, posts }) {
const existingObject = state.postsCache[channelId]
const newObject = existingObject != null ? existingObject : deepCopy(defaultCacheEntryValueForForOneChannel)
const newObject = existingObject ?? { posts: null }
if (posts != null) { newObject.posts = posts }
state.postsCache[channelId] = newObject
},
Expand Down

0 comments on commit 598d970

Please sign in to comment.