Skip to content

Commit 48fcd45

Browse files
committed
debug on saving data & error throw if dataStore get wrong data
1 parent 5cfc418 commit 48fcd45

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

browser/lib/dataStore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ export function getData () {
110110
}
111111

112112
export function setArticles (articles) {
113+
if (!_.isArray(articles)) throw new Error('Articles must be an array')
113114
let data = getData()
114115
data.articles = articles
115116
jetpack.write(getLocalPath(), data)
116117
}
117118

118119
export function setFolders (folders) {
120+
if (!_.isArray(folders)) throw new Error('Folders must be an array')
119121
let data = getData()
120122
data.folders = folders
121123
jetpack.write(getLocalPath(), data)

browser/main/reducer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,16 @@ function articles (state = initialArticles, action) {
226226
let modifiedIndex = _.findIndex(state.modified, _article => articleKey === _article.key)
227227
if (modifiedIndex >= 0) state.modified.splice(modifiedIndex, 1)
228228

229-
dataStore.setArticles(state)
229+
dataStore.setArticles(state.data)
230230
return state
231231
}
232232
case FOLDER_DESTROY:
233233
{
234234
let folderKey = action.data.key
235235

236-
state = state.filter(article => article.FolderKey !== folderKey)
236+
state.data = state.data.filter(article => article.FolderKey !== folderKey)
237237

238-
dataStore.setArticles(state)
238+
dataStore.setArticles(state.data)
239239
return state
240240
}
241241
default:

0 commit comments

Comments
 (0)