Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(replacement.relationships).forEach(field => {
let data = deepGet(replacement, ['relationships', field, 'data']);
if (data !== undefined) {
let currentData = deepGet(current, [
'relationships',
field,
'data'
]);
let relationshipChanged;
if (Array.isArray(data)) {
if (currentData) {
relationshipChanged = !equalRecordIdentitySets(
currentData,
data
);
} else {
relationshipChanged = true;
currentData = [];
}
} else {
if (currentData) {
relationshipChanged = !equalRecordIdentities(currentData, data);
} else {
relationshipChanged = true;
currentData = null;
}
}
Object.keys(replacement.relationships).forEach(field => {
let data = deepGet(replacement, ['relationships', field, 'data']);
if (data !== undefined) {
let currentData = deepGet(current, [
'relationships',
field,
'data'
]);
let relationshipChanged;
if (Array.isArray(data)) {
if (currentData) {
relationshipChanged = !equalRecordIdentitySets(
currentData,
data
);
} else {
relationshipChanged = true;
currentData = [];
}
} else {
if (currentData) {
relationshipChanged = !equalRecordIdentities(currentData, data);
} else {
relationshipChanged = true;
currentData = null;
}
}
replaceRelatedRecords(
cache: SyncRecordAccessor,
op: ReplaceRelatedRecordsOperation
): RecordOperation | undefined {
const { record, relationship, relatedRecords } = op;
const currentRelatedRecords = cache.getRelatedRecordsSync(
record,
relationship
);
if (
currentRelatedRecords === undefined ||
!equalRecordIdentitySets(currentRelatedRecords, relatedRecords)
) {
return {
op: 'replaceRelatedRecords',
record,
relationship,
relatedRecords: currentRelatedRecords || []
};
}
return;
},
async replaceRelatedRecords(
cache: AsyncRecordAccessor,
op: ReplaceRelatedRecordsOperation
): Promise {
const { record, relationship, relatedRecords } = op;
const currentRelatedRecords = await cache.getRelatedRecordsAsync(
record,
relationship
);
if (
currentRelatedRecords === undefined ||
!equalRecordIdentitySets(currentRelatedRecords, relatedRecords)
) {
return {
op: 'replaceRelatedRecords',
record,
relationship,
relatedRecords: currentRelatedRecords || []
};
}
return;
},