Skip to content

Commit

Permalink
fix(feed): keep downloading values seperate
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jun 27, 2018
1 parent 886c4d1 commit 8d04df4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ module.exports = async ({
}, 24 * 60 * 60 * 1000);


const mergeTorrentsWithDownloads = (torrents) => {
const mergeTorrentsWithDownloads = (torrents, copy) => {
if(!torrents)
return torrents

if(copy)
torrents = _.cloneDeep(torrents)

const mergeTorrent = (torrent) => {
const id = torrentClientHashMap[torrent.hash]
if(id)
Expand Down Expand Up @@ -65,10 +68,10 @@ module.exports = async ({
return torrents
}

const mergeTorrentsWithDownloadsFn = (Fn) => (...args) => {
const mergeTorrentsWithDownloadsFn = (Fn, copy) => (...args) => {
const callback = args[args.length - 1]
const rest = args.slice(0, -1)
Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data)))
Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data, copy)))
}

recive('recentTorrents', function(callback)
Expand Down Expand Up @@ -867,7 +870,7 @@ module.exports = async ({
{
callback(feed.feed)
}
recive('feed', mergeTorrentsWithDownloadsFn(feedCall));
recive('feed', mergeTorrentsWithDownloadsFn(feedCall, true)); // don't overwrite feed value

p2p.on('feed', ({}, callback) => {
feedCall((data) => callback(data))
Expand Down

0 comments on commit 8d04df4

Please sign in to comment.