• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript utils.clone函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:29,代码来源:request-settings.ts


示例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'
    );
  });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:29,代码来源:memory-source-test.ts


示例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;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:9,代码来源:request-settings.ts


示例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
   );
 });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:11,代码来源:memory-cache.ts


示例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;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:16,代码来源:request-settings.ts


示例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
     );
   }
 }
开发者ID:orbitjs,项目名称:orbit.js,代码行数:17,代码来源:example-async-record-cache.ts


示例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'
    );
  });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:42,代码来源:memory-cache-test.ts


示例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(
开发者ID:orbitjs,项目名称:orbit.js,代码行数:30,代码来源:sync-patch-operators.ts


示例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);
 }
开发者ID:SmuliS,项目名称:orbit.js,代码行数:6,代码来源:inverse-relationship-accessor.ts


示例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);
开发者ID:orbitjs,项目名称:orbit.js,代码行数:30,代码来源:transform-requests.ts



注:本文中的@orbit/utils.clone函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils.deepSet函数代码示例发布时间:2022-05-28
下一篇:
TypeScript utils.assert函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap