當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Schema.getModel方法代碼示例

本文整理匯總了TypeScript中@orbit/data.Schema.getModel方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Schema.getModel方法的具體用法?TypeScript Schema.getModel怎麽用?TypeScript Schema.getModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@orbit/data.Schema的用法示例。


在下文中一共展示了Schema.getModel方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: recordRemoved

export function recordRemoved(
  schema: Schema,
  record: Record
): RecordOperation[] {
  const ops: RecordOperation[] = [];
  const relationships = record && record.relationships;

  if (relationships) {
    const modelDef = schema.getModel(record.type);
    const recordIdentity = cloneRecordIdentity(record);

    Object.keys(relationships).forEach(relationship => {
      const relationshipDef = modelDef.relationships[relationship];
      const relationshipData =
        relationships[relationship] && relationships[relationship].data;
      const relatedRecords = recordArrayFromData(relationshipData);

      Array.prototype.push.apply(
        ops,
        removeRelatedRecordsOps(
          schema,
          recordIdentity,
          relationshipDef,
          relatedRecords
        )
      );
    });
  }

  return ops;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:31,代碼來源:schema-consistency-utils.ts

示例2: normalizeRecordProperties

export default function normalizeRecordProperties(
  schema: Schema,
  properties: Record<string, unknown>
) {
  const { id, type } = properties;
  const modelDefinition = schema.getModel(type as string);
  const record = { id, type } as OrbitRecord;

  assignKeys(modelDefinition, record, properties);
  assignAttributes(modelDefinition, record, properties);
  assignRelationships(modelDefinition, record, properties);

  return record;
}
開發者ID:orbitjs,項目名稱:ember-orbit,代碼行數:14,代碼來源:normalize-record-properties.ts

示例3: recordReplaced

export function recordReplaced(
  schema: Schema,
  currentRecord: Record,
  record: Record
): RecordOperation[] {
  const ops: RecordOperation[] = [];

  if (record.relationships) {
    const modelDef = schema.getModel(record.type);
    const recordIdentity = cloneRecordIdentity(record);

    for (let relationship in record.relationships) {
      const relationshipDef = modelDef.relationships[relationship];
      const relationshipData =
        record && deepGet(record, ['relationships', relationship, 'data']);
      const currentRelationshipData =
        currentRecord &&
        deepGet(currentRecord, ['relationships', relationship, 'data']);

      if (relationshipDef.type === 'hasMany') {
        Array.prototype.push.apply(
          ops,
          relatedRecordsReplaced(
            schema,
            recordIdentity,
            relationship,
            currentRelationshipData,
            relationshipData
          )
        );
      } else {
        Array.prototype.push.apply(
          ops,
          relatedRecordReplaced(
            schema,
            recordIdentity,
            relationship,
            currentRelationshipData,
            relationshipData
          )
        );
      }
    }
  }

  return ops;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:47,代碼來源:schema-consistency-utils.ts

示例4: removeRelationshipOp

export function removeRelationshipOp(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
): RecordOperation {
  const relationshipDef = schema.getModel(record.type).relationships[
    relationship
  ];
  const isHasMany = relationshipDef.type === 'hasMany';

  return {
    op: isHasMany ? 'removeFromRelatedRecords' : 'replaceRelatedRecord',
    record,
    relationship,
    relatedRecord: isHasMany ? relatedRecord : null
  } as RecordOperation;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:18,代碼來源:schema-consistency-utils.ts

示例5: getInverseRelationship

export function getInverseRelationship(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
): RecordRelationshipIdentity {
  if (relatedRecord) {
    const relationshipDef = schema.getModel(record.type).relationships[
      relationship
    ];
    if (relationshipDef.inverse) {
      return {
        record,
        relationship,
        relatedRecord
      };
    }
  }
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:19,代碼來源:cache-integrity-utils.ts

示例6:

 inverseRelationships.forEach(rel => {
   const relationshipDef = schema.getModel(rel.record.type).relationships[
     rel.relationship
   ];
   if (relationshipDef.type === 'hasMany') {
     ops.push({
       op: 'removeFromRelatedRecords',
       record: rel.record,
       relationship: rel.relationship,
       relatedRecord: rel.relatedRecord
     });
   } else {
     ops.push({
       op: 'replaceRelatedRecord',
       record: rel.record,
       relationship: rel.relationship,
       relatedRecord: null
     });
   }
 });
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:20,代碼來源:cache-integrity-utils.ts

示例7: relatedRecordsReplaced

export function relatedRecordsReplaced(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  currentRelatedRecords: RecordIdentity[],
  relatedRecords: RecordIdentity[]
): RecordOperation[] {
  const ops: RecordOperation[] = [];
  const relationshipDef = schema.getModel(record.type).relationships[
    relationship
  ];

  let addedRecords;

  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;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:39,代碼來源:schema-consistency-utils.ts

示例8: relatedRecordAdded

export function relatedRecordAdded(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
): RecordOperation[] {
  const ops: RecordOperation[] = [];

  if (relatedRecord) {
    const relationshipDef = schema.getModel(record.type).relationships[
      relationship
    ];
    const inverseRelationship = relationshipDef.inverse;

    if (inverseRelationship) {
      ops.push(
        addRelationshipOp(schema, relatedRecord, inverseRelationship, record)
      );
    }
  }

  return ops;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:23,代碼來源:schema-consistency-utils.ts

示例9: getInverseRelationships

export function getInverseRelationships(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecords: RecordIdentity[]
): RecordRelationshipIdentity[] {
  if (relatedRecords && relatedRecords.length > 0) {
    const relationshipDef = schema.getModel(record.type).relationships[
      relationship
    ];
    if (relationshipDef.inverse) {
      const recordIdentity = cloneRecordIdentity(record);

      return relatedRecords.map(relatedRecord => {
        return {
          record: recordIdentity,
          relationship,
          relatedRecord
        };
      });
    }
  }
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:23,代碼來源:cache-integrity-utils.ts

示例10: relatedRecordReplaced

export function relatedRecordReplaced(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  currentRelatedRecord: RecordIdentity,
  relatedRecord: RecordIdentity
): RecordOperation[] {
  const ops: RecordOperation[] = [];

  if (!equalRecordIdentities(relatedRecord, currentRelatedRecord)) {
    const relationshipDef = schema.getModel(record.type).relationships[
      relationship
    ];
    const inverseRelationship = relationshipDef.inverse;

    if (inverseRelationship) {
      if (currentRelatedRecord) {
        ops.push(
          removeRelationshipOp(
            schema,
            currentRelatedRecord,
            inverseRelationship,
            record
          )
        );
      }

      if (relatedRecord) {
        ops.push(
          addRelationshipOp(schema, relatedRecord, inverseRelationship, record)
        );
      }
    }
  }

  return ops;
}
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:37,代碼來源:schema-consistency-utils.ts


注:本文中的@orbit/data.Schema.getModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。