diff --git a/browser/main/store.js b/browser/main/store.js index ed1b08d7..a4c1594d 100644 --- a/browser/main/store.js +++ b/browser/main/store.js @@ -58,14 +58,7 @@ function data (state = defaultDataMap(), action) { state.noteMap = new Map(state.noteMap) state.noteMap.set(uniqueKey, note) - if (oldNote == null || oldNote.isStarred !== note.isStarred) { - state.starredSet = new Set(state.starredSet) - if (note.isStarred) { - state.starredSet.add(uniqueKey) - } else { - state.starredSet.delete(uniqueKey) - } - } + updateStarredChange(oldNote, note, state, uniqueKey) if (oldNote == null || oldNote.isTrashed !== note.isTrashed) { state.trashedSet = new Set(state.trashedSet) @@ -164,14 +157,7 @@ function data (state = defaultDataMap(), action) { removeFromTags(originNote.tags, state, originKey) } - if (oldNote == null || oldNote.isStarred !== note.isStarred) { - state.starredSet = new Set(state.starredSet) - if (note.isStarred) { - state.starredSet.add(uniqueKey) - } else { - state.starredSet.delete(uniqueKey) - } - } + updateStarredChange(oldNote, note, state, uniqueKey) if (oldNote == null || oldNote.isTrashed !== note.isTrashed) { state.trashedSet = new Set(state.trashedSet) @@ -444,6 +430,17 @@ function status (state = defaultStatus, action) { return state } +function updateStarredChange (oldNote, note, state, uniqueKey) { + if (oldNote == null || oldNote.isStarred !== note.isStarred) { + state.starredSet = new Set(state.starredSet) + if (note.isStarred) { + state.starredSet.add(uniqueKey) + } else { + state.starredSet.delete(uniqueKey) + } + } +} + function updateTagChanges (oldNote, note, state, uniqueKey) { const discardedTags = _.difference(oldNote.tags, note.tags) const addedTags = _.difference(note.tags, oldNote.tags)