Skip to content

Commit

Permalink
sending items with updated parents (finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszn committed Nov 4, 2017
1 parent e722432 commit 41b6a1e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions js/wq/outbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ function _Outbox(store) {
self.sendItem = function(item, once) {
if (!item || item.synced) {
return Promise.resolve(null);
} else if (item.parents && item.parents.length) {
return Promise.resolve(item);
}

var data = item.data;
Expand Down Expand Up @@ -407,15 +405,22 @@ function _Outbox(store) {

var funcs = items.map(function(a) {
return function() {
return self.sendItem(a).then(function(item) {
if (item && !item.synced) {
// sendItem did not result in sync
item.retryCount = item.retryCount || 0;
item.retryCount++;
}
return item;
}).then(function(item) {
return self.model.update([item]);
// "a".data could have been updated after syncing its parents
// let's fetch it again
return self.unsyncedItems(a.id).then(function(allUnsynced) {
var updated = allUnsynced.filter(function(item) {
return item.id == a.id; })[0];
a.data = updated.data;
return self.sendItem(a).then(function(item) {
if (item && !item.synced) {
// sendItem did not result in sync
item.retryCount = item.retryCount || 0;
item.retryCount++;
}
return item;
}).then(function(item) {
return self.model.update([item]);
});
});
};
});
Expand Down

0 comments on commit 41b6a1e

Please sign in to comment.