Skip to content

Commit

Permalink
Don't change state when distance hasn't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonpage committed Nov 19, 2016
1 parent b72380f commit e8bf061
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,24 @@ function itemUpdated(state, id, { distance }) {

if (!previous) return state;

const item = {
const next = {
...previous,
value: {
...previous.value,
...normalizeDistance(distance, previous.value),
},
};

// right now the only item update possible is distance,
// if that hasn't changed, abort to prevent react rerendering
const distanceChanged = next.value.distance !== previous.value.distance;
if (!distanceChanged) return state;

return {
...state,
items: {
...items,
[id]: item,
[id]: next,
},
};
}
Expand Down

0 comments on commit e8bf061

Please sign in to comment.