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


TypeScript data.cloneRecordIdentity函數代碼示例

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