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

TypeScript data.cloneRecordIdentity函数代码示例

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript data.equalRecordIdentities函数代码示例发布时间:2022-05-28
下一篇:
TypeScript data.buildTransform函数代码示例发布时间: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