Skip to content

Commit

Permalink
preserve first prev
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Nov 12, 2024
1 parent 35f1941 commit c941317
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/stash/src/actions/applyUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ export function applyUpdates({ stash, updates }: ApplyUpdatesArgs): void {
delete tableState[encodedKey];
}

// apply update to store update for notifying subscribers
((storeUpdates.records[table.namespaceLabel] ??= {})[table.label] ??= {})[encodedKey] = {
prev: prevRecord,
// add update to pending updates for notifying subscribers
const prevUpdate = storeUpdates.records[table.namespaceLabel]?.[table.label]?.[encodedKey];
const update = {
// preserve the initial prev state if we already have a pending update
// TODO: change subscribers to an array of updates instead of an object
prev: prevUpdate ? prevUpdate.prev : prevRecord,
current: nextRecord,
};
((storeUpdates.records[table.namespaceLabel] ??= {})[table.label] ??= {})[encodedKey] ??= update;
}

queueMicrotask(() => {
Expand Down

0 comments on commit c941317

Please sign in to comment.