当前位置: 首页>>代码示例>>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;未经允许,请勿转载。