How to use the @orbit/data.equalRecordIdentities 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 sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / json-api.service.ts View on Github external
case 'replaceRelatedRecord':
          const updateRelated = operation as
            | AddToRelatedRecordsOperation
            | RemoveFromRelatedRecordsOperation
            | ReplaceRelatedRecordsOperation
            | ReplaceRelatedRecordOperation;
          transformRecords.push([updateRelated.record, updateRelated.relationship]);
          break;
      }

      for (const [transformRecord, transformRelationship] of transformRecords) {
        // check if the transformed record matches record being queried
        // if performing a related record query, ensure that the transformed relationship matches the queried
        // relationship
        if (
          equalRecordIdentities(queryRecord, transformRecord) &&
          (queryRelationship == null || queryRelationship.name === transformRelationship)
        ) {
          return true;
        }

        // check if the type of the transformed record matches the type being queried
        if (queryType === transformRecord.type) {
          return true;
        }

        // check if the type of the transformed record matches one of the included types
        if (includedTypes.has(transformRecord.type)) {
          return true;
        }

        // check if the transformed record is one of the related records being queried
github orbitjs / orbit / packages / @orbit / memory / src / memory-cache.ts View on Github external
rel =>
            !(
              equalRecordIdentities(rel.record, r.record) &&
              rel.relationship === r.relationship
            )
        );
github orbitjs / orbit / packages / @orbit / jsonapi / src / lib / transform-requests.ts View on Github external
transform.operations.forEach((operation: RecordOperation) => {
    let request;
    let newRequestNeeded = true;

    if (
      prevRequest &&
      equalRecordIdentities(prevRequest.record, operation.record)
    ) {
      if (operation.op === 'removeRecord') {
        newRequestNeeded = false;

        if (prevRequest.op !== 'removeRecord') {
          prevRequest = null;
          requests.pop();
        }
      } else if (
        prevRequest.op === 'addRecord' ||
        prevRequest.op === 'updateRecord'
      ) {
        if (operation.op === 'replaceAttribute') {
          newRequestNeeded = false;
          replaceRecordAttribute(
            prevRequest.record,
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / async-inverse-patch-operators.ts View on Github external
async replaceRelatedRecord(
    cache: AsyncRecordAccessor,
    op: ReplaceRelatedRecordOperation
  ): Promise {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecord = await cache.getRelatedRecordAsync(
      record,
      relationship
    );

    if (
      currentRelatedRecord === undefined ||
      !equalRecordIdentities(
        currentRelatedRecord as RecordIdentity,
        relatedRecord as RecordIdentity
      )
    ) {
      return {
        op: 'replaceRelatedRecord',
        record,
        relationship,
        relatedRecord: currentRelatedRecord || null
      };
    }
    return;
  }
};
github sillsdev / web-languageforge / src / SIL.XForge.Scripture / ClientApp / src / xforge-common / json-api.service.ts View on Github external
private isRelated(recRel: RecordRelationship, record: Record): boolean {
    if (recRel.data instanceof Array) {
      if (recRel.data.some(r => equalRecordIdentities(r, record))) {
        return true;
      }
    } else if (equalRecordIdentities(recRel.data, record)) {
      return true;
    }
    return false;
  }
}
github orbitjs / orbit / packages / @orbit / store / src / cache / patch-transforms.ts View on Github external
        relatedRecords = relatedRecords.filter(r => !equalRecordIdentities(r, op.relatedRecord));
github orbitjs / orbit / packages / @orbit / local-storage / src / lib / transform-operators.ts View on Github external
removeFromRelatedRecords(source: Source, operation: RemoveFromRelatedRecordsOperation) {
    let record: Record = source.getRecord(operation.record);
    if (record) {
      let relationships = deepGet(record, ['relationships', operation.relationship, 'data']) as RecordIdentity[];
      if (relationships) {
        for (let i = 0, l = relationships.length; i < l; i++) {
          if (equalRecordIdentities(relationships[i], operation.relatedRecord)) {
            relationships.splice(i, 1);
            break;
          }
        }
        return source.putRecord(record);
      }
    }
  },
github orbitjs / orbit / packages / @orbit / record-cache / src / operators / sync-inverse-patch-operators.ts View on Github external
replaceRelatedRecord(
    cache: SyncRecordAccessor,
    op: ReplaceRelatedRecordOperation
  ): RecordOperation | undefined {
    const { record, relationship, relatedRecord } = op;
    const currentRelatedRecord = cache.getRelatedRecordSync(
      record,
      relationship
    );

    if (
      currentRelatedRecord === undefined ||
      !equalRecordIdentities(
        currentRelatedRecord as RecordIdentity,
        relatedRecord as RecordIdentity
      )
    ) {
      return {
        op: 'replaceRelatedRecord',
        record,
        relationship,
        relatedRecord: currentRelatedRecord || null
      };
    }
    return;
  }
};