Skip to content

Commit

Permalink
(hotfix): merge persisted mangas with fetched ones
Browse files Browse the repository at this point in the history
- previously fetched mangas would just overwrite the existing mangas
  - now that we have important data like chapter read/unread & new
    tracking, we can't just overwrite, have to merge them together

- this is a bit of an edge case as the only time there's a conflict is
  when a favorited manga also appears in the Latest or Search list
  - but it certainly does happen, I just experienced it!
    - had chapters overwritten to an empty list bc manga was in Latest
  • Loading branch information
agilgur5 committed Nov 23, 2019
1 parent 70e204d commit 2f15e1a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ const AppModel = types.model('App', {
return self.favorites.includes(self.selectedManga)
}
})).actions((self) => {
// private helper functions
function mergeManga (manga) {
const oldManga = self.mangas.get(manga.link)
self.mangas.put({...oldManga, ...manga})
}

function addMangas (mangas) {
mangas.forEach(manga => self.mangas.put(manga))
mangas.forEach(mergeManga)
}

function mangasToRefs (mangas) {
return mangas.map(({link}) => link)
}

// public actions
return {toggleHorizontal () {
self.isHorizontal = !self.isHorizontal
},
Expand Down

0 comments on commit 2f15e1a

Please sign in to comment.