Skip to content

Commit

Permalink
fix: update variable name isCompatible
Browse files Browse the repository at this point in the history
Signed-off-by: dominictb <tb-dominic@outlook.com>
  • Loading branch information
dominictb committed Apr 25, 2024
1 parent 5b64707 commit 4938414
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions lib/Onyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ function disconnect(connectionID: number, keyToRemoveFromEvictionBlocklist?: Ony
function set<TKey extends OnyxKey>(key: TKey, value: OnyxEntry<KeyValueMapping[TKey]>): Promise<void> {
// check if the value is compatible with the existing value in the storage
const existingValue = cache.getValue(key, false);
const {compatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(value, existingValue);
if (!compatible) {
const {isCompatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(value, existingValue);
if (!isCompatible) {
Logger.logAlert(logMessages.incompatibleUpdateAlert(key, 'set', existingValueType, newValueType));
return Promise.resolve();
}
Expand Down Expand Up @@ -245,6 +245,7 @@ function set<TKey extends OnyxKey>(key: TKey, value: OnyxEntry<KeyValueMapping[T
return updatePromise;
});
}

/**
* Sets multiple keys and values
*
Expand Down Expand Up @@ -316,11 +317,11 @@ function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxEntry<NullishDeep<K
// We first only merge the changes, so we can provide these to the native implementation (SQLite uses only delta changes in "JSON_PATCH" to merge)
// We don't want to remove null values from the "batchedDeltaChanges", because SQLite uses them to remove keys from storage natively.
const validChanges = mergeQueue[key].filter((change) => {
const {compatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(change, existingValue);
if (!compatible) {
const {isCompatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(change, existingValue);
if (!isCompatible) {
Logger.logAlert(logMessages.incompatibleUpdateAlert(key, 'merge', existingValueType, newValueType));
}
return compatible;
return isCompatible;
});

if (!validChanges.length) {
Expand Down Expand Up @@ -431,8 +432,8 @@ function mergeCollection<TKey extends CollectionKeyBase, TMap>(collectionKey: TK
const newKeys = keys.filter((key) => !persistedKeys.has(key));

const existingKeyCollection = existingKeys.reduce((obj: NullableKeyValueMapping, key) => {
const {compatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(mergedCollection[key], cachedCollectionForExistingKeys[key]);
if (!compatible) {
const {isCompatible, existingValueType, newValueType} = utils.checkCompatibilityWithExistingValue(mergedCollection[key], cachedCollectionForExistingKeys[key]);
if (!isCompatible) {
Logger.logAlert(logMessages.incompatibleUpdateAlert(key, 'mergeCollection', existingValueType, newValueType));
return obj;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ function formatActionName(method: string, key?: OnyxKey): string {
}

/** validate that the update and the existing value are compatible */
function checkCompatibilityWithExistingValue(value: unknown, existingValue: unknown): {compatible: boolean; existingValueType?: string; newValueType?: string} {
function checkCompatibilityWithExistingValue(value: unknown, existingValue: unknown): {isCompatible: boolean; existingValueType?: string; newValueType?: string} {
if (!existingValue || !value) {
return {
compatible: true,
isCompatible: true,
};
}
const existingValueType = Array.isArray(existingValue) ? 'array' : 'non-array';
const newValueType = Array.isArray(value) ? 'array' : 'non-array';
if (existingValueType !== newValueType) {
return {
compatible: false,
isCompatible: false,
existingValueType,
newValueType,
};
}
return {
compatible: true,
isCompatible: true,
};
}

Expand Down

0 comments on commit 4938414

Please sign in to comment.