本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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
};
}
}
}
示例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
});
}
});
示例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;
}
示例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;
}
示例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
};
});
}
}
}
示例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;
}