本文整理汇总了TypeScript中@orbit/data.cloneRecordIdentity函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cloneRecordIdentity函数的具体用法?TypeScript cloneRecordIdentity怎么用?TypeScript cloneRecordIdentity使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cloneRecordIdentity函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: test
test('remove record with hasMany relationships', function(assert) {
const earth = { type: 'planet', id: 'earth', relationships: { inhabitants: { data: [{ type: 'inhabitant', id: 'human' }] } } };
const human = { type: 'inhabitant', id: 'human', relationships: { planets: { data: [{ type: 'planet', id: 'earth' }] } } };
cache.patch(t => [
t.addRecord(earth),
t.addRecord(human)
]);
assert.deepEqual(cache.inverseRelationships.all(earth), [{
record: { type: 'inhabitant', id: 'human' },
relationship: 'planets'
}]);
assert.deepEqual(cache.inverseRelationships.all(human), [{
record: { type: 'planet', id: 'earth' },
relationship: 'inhabitants'
}]);
const removeInhabitantOp = {
op: 'removeRecord',
record: human
};
assert.deepEqual(
processor.before(removeInhabitantOp),
[]
);
assert.deepEqual(
processor.after(removeInhabitantOp),
[
{
op: 'removeFromRelatedRecords',
record: cloneRecordIdentity(earth),
relationship: 'inhabitants',
relatedRecord: cloneRecordIdentity(human)
}
]
);
assert.deepEqual(
processor.finally(removeInhabitantOp),
[]
);
assert.deepEqual(cache.inverseRelationships.all(earth), []);
assert.deepEqual(cache.inverseRelationships.all(human), []);
});
开发者ID:SmuliS,项目名称:orbit.js,代码行数:49,代码来源:cache-integrity-processor-test.ts
示例2: getAllInverseRelationships
export function getAllInverseRelationships(
record: Record
): RecordRelationshipIdentity[] {
const relationships = record && record.relationships;
if (relationships) {
const recordIdentity = cloneRecordIdentity(record);
const inverseRelationships: RecordRelationshipIdentity[] = [];
Object.keys(relationships).forEach(relationship => {
const relationshipData =
relationships[relationship] && relationships[relationship].data;
if (relationshipData) {
if (isArray(relationshipData)) {
const relatedRecords = relationshipData as Record[];
relatedRecords.forEach(relatedRecord => {
inverseRelationships.push({
record: recordIdentity,
relationship,
relatedRecord
});
});
} else {
const relatedRecord = relationshipData as Record;
inverseRelationships.push({
record: recordIdentity,
relationship,
relatedRecord
});
}
}
});
return inverseRelationships;
}
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:35,代码来源:cache-integrity-utils.ts
示例3: clearInverseRelationshipOps
private clearInverseRelationshipOps(record: RecordIdentity): RecordOperation[] {
const ops: RecordOperation[] = [];
const inverseRels = this.cache.inverseRelationships.all(record);
if (inverseRels.length > 0) {
const recordIdentity = cloneRecordIdentity(record);
inverseRels.forEach(rel => {
const relationshipDef = this.cache.schema.getModel(rel.record.type).relationships[rel.relationship];
if (relationshipDef.type === 'hasMany') {
ops.push({
op: 'removeFromRelatedRecords',
record: rel.record,
relationship: rel.relationship,
relatedRecord: recordIdentity
});
} else {
ops.push({
op: 'replaceRelatedRecord',
record: rel.record,
relationship: rel.relationship,
relatedRecord: null
});
}
});
}
return ops;
}
开发者ID:SmuliS,项目名称:orbit.js,代码行数:28,代码来源:cache-integrity-processor.ts
示例4: 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
示例5: test
test('replace hasMany => hasMany, clearing records', function(assert) {
const human = {
type: 'inhabitant',
id: 'human',
relationships: { planets: { data: [{ type: 'planet', id: 'earth' }] } }
};
const earth = {
type: 'planet',
id: 'earth',
relationships: {
inhabitants: { data: [{ type: 'inhabitant', id: 'human' }] }
}
};
cache.patch(t => [t.addRecord(earth), t.addRecord(human)]);
const clearInhabitantsOp: ReplaceRelatedRecordsOperation = {
op: 'replaceRelatedRecords',
record: identity(earth),
relationship: 'inhabitants',
relatedRecords: []
};
assert.deepEqual(processor.after(clearInhabitantsOp), [
{
op: 'removeFromRelatedRecords',
record: identity(human),
relationship: 'planets',
relatedRecord: identity(earth)
}
]);
assert.deepEqual(processor.finally(clearInhabitantsOp), []);
});
开发者ID:orbitjs,项目名称:orbit.js,代码行数:34,代码来源:schema-consistency-processor-test.ts
示例6: test
test('replace hasMany => hasOne with populated array, when already populated', function(assert) {
const saturn = { type: 'planet', id: 'saturn',
attributes: { name: 'Saturn' },
relationships: { moons: { data: [{ type: 'moon', id: 'titan' }] } } };
const jupiter = { type: 'planet', id: 'jupiter',
attributes: { name: 'Jupiter' },
relationships: { moons: { data: [{ type: 'moon', id: 'europa' }] } } };
const titan = { type: 'moon', id: 'titan',
attributes: { name: 'Titan' },
relationships: { planet: { data: { type: 'planet', id: 'saturn' } } } };
const europa = { type: 'moon', id: 'europa',
attributes: { name: 'Europa' },
relationships: { planet: { data: { type: 'planet', id: 'jupiter' } } } };
cache.patch(t => [
t.addRecord(saturn),
t.addRecord(jupiter),
t.addRecord(titan),
t.addRecord(europa)
]);
const replaceMoonsOp = {
op: 'replaceRelatedRecords',
record: identity(saturn),
relationship: 'moons',
relatedRecords: [identity(europa)]
};
assert.deepEqual(
processor.before(replaceMoonsOp),
[]
);
assert.deepEqual(
processor.after(replaceMoonsOp),
[
{
op: 'replaceRelatedRecord',
record: identity(titan),
relationship: 'planet',
relatedRecord: null
},
{
op: 'replaceRelatedRecord',
record: identity(europa),
relationship: 'planet',
relatedRecord: identity(saturn)
}
]
);
assert.deepEqual(
processor.finally(replaceMoonsOp),
[]
);
});
开发者ID:SmuliS,项目名称:orbit.js,代码行数:59,代码来源:schema-consistency-processor-test.ts
示例7: identity
.then(() => {
assert.deepEqual(
rollbackOperations,
[
{ op: 'removeRecord', record: identity(recordE) },
{ op: 'removeRecord', record: identity(recordD) },
{ op: 'removeRecord', record: identity(recordC) },
{ op: 'removeRecord', record: identity(recordB) }
],
'emits inverse operations in correct order'
);
assert.equal(store.transformLog.head, addRecordATransform.id, 'rolls back transform log');
});
开发者ID:SmuliS,项目名称:orbit.js,代码行数:14,代码来源:store-test.ts
注:本文中的@orbit/data.cloneRecordIdentity函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论