本文整理匯總了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;
}