How to use the @orbit/data.uniqueRecordIdentities function in @orbit/data

To help you get started, we’ve selected a few @orbit/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orbitjs / orbit / packages / @orbit / record-cache / src / operation-processors / utils / schema-consistency-utils.ts View on Github external
export function relatedRecordsReplaced(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecords: RecordIdentity[],
  currentRelatedRecords?: RecordIdentity[]
): RecordOperation[] {
  const ops: RecordOperation[] = [];
  const relationshipDef = schema.getRelationship(record.type, relationship);

  let addedRecords: RecordIdentity[];

  if (currentRelatedRecords && currentRelatedRecords.length > 0) {
    let removedRecords = uniqueRecordIdentities(
      currentRelatedRecords,
      relatedRecords
    );
    Array.prototype.push.apply(
      ops,
      removeRelatedRecordsOps(schema, record, relationshipDef, removedRecords)
    );

    addedRecords = uniqueRecordIdentities(
      relatedRecords,
      currentRelatedRecords
    );
  } else {
    addedRecords = relatedRecords;
  }
github orbitjs / orbit / packages / @orbit / record-cache / src / operation-processors / utils / schema-consistency-utils.ts View on Github external
const ops: RecordOperation[] = [];
  const relationshipDef = schema.getRelationship(record.type, relationship);

  let addedRecords: RecordIdentity[];

  if (currentRelatedRecords && currentRelatedRecords.length > 0) {
    let removedRecords = uniqueRecordIdentities(
      currentRelatedRecords,
      relatedRecords
    );
    Array.prototype.push.apply(
      ops,
      removeRelatedRecordsOps(schema, record, relationshipDef, removedRecords)
    );

    addedRecords = uniqueRecordIdentities(
      relatedRecords,
      currentRelatedRecords
    );
  } else {
    addedRecords = relatedRecords;
  }

  Array.prototype.push.apply(
    ops,
    addRelatedRecordsOps(schema, record, relationshipDef, addedRecords)
  );

  return ops;
}