Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Mar 5, 2024
1 parent 748c51f commit d0d261b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1606,13 +1606,14 @@ function update(data) {
updateQueue,
(acc, operations, key) => {
// If the first operation is a set, we want to use that as the existing value.
// Only the first operation can be a `set`, since when enqueuing the operations, we clear the whole queue each time a set is enqueued.
// Only the first operation can be a `set`, since when enqueuing the operations, we clear the whole queue each time a `set` is enqueued.
const existingValue = operations[0].onyxMethod === METHOD.SET ? operations[0].value : existingSnapshot[key];

// Remove the first operation if it was a set, since we already used it to get the existing value.
// Remove the first operation if it was a `set`, since we already used it to get the existing value.
const mergeOperations = _.filter(operations, ({onyxMethod}) => onyxMethod === METHOD.MERGE);

// If there are no merge operations, it means only a single set operation was enqueued, and we should use the existing value.
// If there are no merge operations, it means only a single `set` operation was enqueued.
// In this case, we should use the existing value.
// Otherwise, apply the merge operations to the existing value.
const updatedValue = _.isEmpty(mergeOperations)
? existingValue
Expand All @@ -1622,7 +1623,7 @@ function update(data) {
true,
);

// If the batched changes equal null, we want to remove the key from storage to reduce the storage size
// If the batched changes equal `null`, we want to remove the key from storage to reduce the storage size.
const {wasRemoved} = removeNullValues(key, updatedValue);
const hasChanged = cache.hasValueChanged(key, updatedValue);
updatesToBroadcast.push(broadcastUpdate(key, updatedValue, 'update', hasChanged, wasRemoved));
Expand Down

0 comments on commit d0d261b

Please sign in to comment.