Skip to content

Commit

Permalink
Be lazy with invisible summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Androbin committed Jul 23, 2018
1 parent f14afd7 commit f652c3c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/data/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,26 @@ const store = {
}

if (updateDom) {
updatedItems.forEach((updatedItem) => {
// TODO (davidg): this is pretty CPU intensive - web worker?
const updateItem = (updatedItem) => {
this.triggerListener(`PIE-${updatedItem.id}`);
});
};

const visibleItems = updatedItems.filter((item) => item.visible);
visibleItems.forEach(updateItem);

const invisibleItems = updatedItems.filter((item) => !item.visible);
const batch = 50;

for (let i = 0; i < invisibleItems.length / batch; i++) {
requestIdleCallback(() => {
invisibleItems.slice(i*batch, (i+1)*batch).forEach(updateItem);
}, { timeout: 1000 });
}
}
},

updateScoreSummary(item, newScoreKey, oldScoreKey) {
// TODO (davidg): this is pretty CPU intensive - web worker?
const newItem = !newScoreKey && !oldScoreKey;
// the score summary holds the aggregate scores for non-leaf nodes
newScoreKey = newScoreKey || SCORES.LEVEL_0.key;
Expand Down

0 comments on commit f652c3c

Please sign in to comment.