當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript utils.clone函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。