本文整理汇总了TypeScript中@orbit/utils.clone函数的典型用法代码示例。如果您正苦于以下问题:TypeScript clone函数的具体用法?TypeScript clone怎么用?TypeScript clone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clone函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildFetchSettings
export function buildFetchSettings(
options: RequestOptions = {},
customSettings?: FetchSettings
): FetchSettings {
let settings = options.settings ? clone(options.settings) : {};
if (customSettings) {
deepMerge(settings, customSettings);
}
['filter', 'include', 'page', 'sort'].forEach(param => {
let value = (options as any)[param];
if (value) {
if (param === 'include' && isArray(value)) {
value = value.join(',');
}
deepSet(settings, ['params', param], value);
}
});
let timeout = (options as any)['timeout'];
if (timeout) {
deprecate('JSONAPI: Specify `timeout` option inside a `settings` object.');
settings.timeout = timeout;
}
return settings;
}
示例2: test
test('#upgrade upgrades the cache to include new models introduced in a schema', async function(assert) {
let person = {
type: 'person',
id: '1',
relationships: { planet: { data: { type: 'planet', id: 'earth' } } }
};
let models = clone(schema.models);
models.planet.relationships.inhabitants = {
type: 'hasMany',
model: 'person',
inverse: 'planet'
};
models.person = {
relationships: {
planet: { type: 'hasOne', model: 'planet', inverse: 'inhabitants' }
}
};
schema.upgrade({ models });
await source.update(t => t.addRecord(person));
assert.deepEqual(
source.cache.getRecordSync({ type: 'person', id: '1' }),
person,
'records match'
);
});
示例3: mergeIncludePaths
function mergeIncludePaths(paths: string[], customPaths: string[]) {
let result = clone(paths);
for (let customPath of customPaths) {
if (!paths.includes(customPath)) {
result.push(customPath);
}
}
return result;
}
示例4: clone
relationships.forEach(r => {
let rels = this._inverseRelationships[r.relatedRecord.type].get(
r.relatedRecord.id
);
rels = rels ? clone(rels) : [];
rels.push(r);
this._inverseRelationships[r.relatedRecord.type].set(
r.relatedRecord.id,
rels
);
});
示例5: mergeFilters
function mergeFilters(filters: Filter[], customFilters: Filter[]) {
let result: Filter[] = clone(filters);
let filterKeys: string[] = filters.map(f => filterKey(f));
for (let customFilter of customFilters) {
let customerFilterKey = filterKey(customFilter);
if (filterKeys.includes(customerFilterKey)) {
let filterToOverride = result.find(
f => filterKey(f) === customerFilterKey
);
setFilterValue(filterToOverride, filterValue(customFilter));
} else {
result.push(customFilter);
}
}
return result;
}
示例6: addInverseRelationshipsAsync
async addInverseRelationshipsAsync(
relationships: RecordRelationshipIdentity[]
): Promise<void> {
for (let relationship of relationships) {
let rels: any = deepGet(this._inverseRelationships, [
relationship.relatedRecord.type,
relationship.relatedRecord.id
]);
rels = rels ? clone(rels) : [];
rels.push(relationship);
deepSet(
this._inverseRelationships,
[relationship.relatedRecord.type, relationship.relatedRecord.id],
rels
);
}
}
示例7: test
test('#upgrade upgrades the cache to include new models introduced in a schema', function(assert) {
let cache = new MemoryCache({ schema, keyMap });
let person = {
type: 'person',
id: '1',
relationships: { planet: { data: { type: 'planet', id: 'earth' } } }
};
assert.throws(() => cache.patch({ op: 'addRecord', record: person }));
let models = clone(schema.models);
models.planet.relationships.inhabitants = {
type: 'hasMany',
model: 'person',
inverse: 'planet'
};
models.person = {
relationships: {
planet: { type: 'hasOne', model: 'planet', inverse: 'inhabitants' }
}
};
schema.upgrade({ models });
cache.upgrade();
cache.patch({ op: 'addRecord', record: person });
assert.deepEqual(
cache.getRecordSync({ type: 'person', id: '1' }),
person,
'records match'
);
assert.deepEqual(
cache.getRelatedRecordSync(person, 'planet'),
{ type: 'planet', id: 'earth' },
'relationship exists'
);
assert.equal(
cache.getInverseRelationshipsSync({ type: 'planet', id: 'earth' }).length,
1,
'inverse relationship exists'
);
});
示例8: removeRecord
removeRecord(
cache: SyncRecordAccessor,
op: RemoveRecordOperation
): PatchResultData {
return cache.removeRecordSync(op.record);
},
replaceKey(
cache: SyncRecordAccessor,
op: ReplaceKeyOperation
): PatchResultData {
let record = cache.getRecordSync(op.record);
if (record) {
record = clone(record);
} else {
record = cloneRecordIdentity(op.record);
}
deepSet(record, ['keys', op.key], op.value);
cache.setRecordSync(record);
if (cache.keyMap) {
cache.keyMap.pushRecord(record);
}
return record;
},
replaceAttribute(
示例9: add
private add(record: RecordIdentity, inverseRelationship: InverseRelationship): void {
let rels = this._relationships[record.type].get(record.id);
rels = rels ? clone(rels) : [];
rels.push(inverseRelationship);
this._relationships[record.type].set(record.id, rels);
}
示例10: addRecord
prevRequest = request;
}
});
return requests;
}
export interface OperationToRequestConverter {
(op: RecordOperation): TransformRecordRequest;
}
const OperationToRequestMap: Dict<OperationToRequestConverter> = {
addRecord(operation: AddRecordOperation): TransformRecordRequest {
return {
op: 'addRecord',
record: clone(operation.record)
};
},
removeRecord(operation: RemoveRecordOperation): TransformRecordRequest {
return {
op: 'removeRecord',
record: cloneRecordIdentity(operation.record)
};
},
replaceAttribute(
operation: ReplaceAttributeOperation
): TransformRecordRequest {
const record = cloneRecordIdentity(operation.record);