Skip to content

Commit

Permalink
return a new array
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jun 6, 2022
1 parent 3556534 commit 2b0e265
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/data/cached-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ export const getRecentWithCache = (
mergeLine(stateHistory.line, cache.data.line);
}
if (stateHistory.timeline.length) {
mergeTimeline(stateHistory.timeline, cache.data.timeline);
// Replace the timeline array to force an update
cache.data.timeline = [...cache.data.timeline];
cache.data.timeline = mergeTimeline(
stateHistory.timeline,
cache.data.timeline
);
}
pruneStartTime(startTime, cache.data);
} else {
Expand Down Expand Up @@ -209,16 +210,18 @@ const mergeTimeline = (
historyTimelines: TimelineEntity[],
cacheTimelines: TimelineEntity[]
) => {
const mergedTimelines: TimelineEntity[] = [];
historyTimelines.forEach((timeline) => {
const oldTimeline = cacheTimelines.find(
(cacheTimeline) => cacheTimeline.entity_id === timeline.entity_id
);
if (oldTimeline) {
oldTimeline.data = oldTimeline.data.concat(timeline.data);
} else {
cacheTimelines.push(timeline);
}
mergedTimelines.push(
oldTimeline
? { ...oldTimeline, data: oldTimeline.data.concat(timeline.data) }
: timeline
);
});
return mergedTimelines;
};

const pruneArray = (originalStartTime: Date, arr) => {
Expand Down

0 comments on commit 2b0e265

Please sign in to comment.