当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript TransformBuilder.addRecord方法代码示例

本文整理汇总了TypeScript中@orbit/data.TransformBuilder.addRecord方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TransformBuilder.addRecord方法的具体用法?TypeScript TransformBuilder.addRecord怎么用?TypeScript TransformBuilder.addRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@orbit/data.TransformBuilder的用法示例。


在下文中一共展示了TransformBuilder.addRecord方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: module

module('EventLoggingStrategy', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform([t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })], null, 'a');
  const tB = buildTransform([t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })], null, 'b');
  const tC = buildTransform([t.addRecord({ type: 'planet', id: 'c', attributes: { name: 'c' } })], null, 'c');

  let eventLoggingStrategy;

  test('can be instantiated', function(assert) {
    eventLoggingStrategy = new EventLoggingStrategy();

    assert.ok(eventLoggingStrategy);
  });

  test('can be added to a coordinator', function(assert) {
    let coordinator = new Coordinator();

    eventLoggingStrategy = new EventLoggingStrategy();

    coordinator.addStrategy(eventLoggingStrategy);

    assert.strictEqual(coordinator.getStrategy('event-logging'), eventLoggingStrategy);
  });

  test('for basic sources, installs `transform` listeners on activatation and removes them on deactivation', function(assert) {
    assert.expect(6);

    class MySource extends Source {}

    let s1 = new MySource({ name: 's1' });
    let s2 = new MySource({ name: 's2' });

    eventLoggingStrategy = new EventLoggingStrategy();

    let coordinator = new Coordinator({ sources: [ s1, s2 ], strategies: [ eventLoggingStrategy ]});

    assert.equal(s1.listeners('transform').length, 0);
    assert.equal(s2.listeners('transform').length, 0);

    return coordinator.activate()
      .then(() => {
        assert.equal(s1.listeners('transform').length, 1);
        assert.equal(s2.listeners('transform').length, 1);

        return coordinator.deactivate();
      })
      .then(() => {
        assert.equal(s1.listeners('transform').length, 0);
        assert.equal(s2.listeners('transform').length, 0);
      });
  });

  // TODO:
  // * test `interfaces` option
  // * test adding sources that support different interfaces to ensure they're inspected properly
});
开发者ID:SmuliS,项目名称:orbit.js,代码行数:56,代码来源:event-logging-strategy-test.ts

示例2: test

    test('addRecord + replaceAttribute => [addRecord]', function(assert) {
      const t = buildTransform([
        tb.addRecord({
          type: 'planet',
          id: 'jupiter',
          attributes: { name: 'Earth' }
        }),
        tb.replaceAttribute(
          { type: 'planet', id: 'jupiter' },
          'atmosphere',
          'gaseous'
        )
      ]);

      assert.deepEqual(getTransformRequests(requestProcessor, t), [
        {
          op: 'addRecord',
          record: {
            type: 'planet',
            id: 'jupiter',
            attributes: { name: 'Earth', atmosphere: 'gaseous' }
          }
        }
      ]);
    });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:25,代码来源:transform-requests-test.ts

示例3: test

    test('addRecord + removeRecord => []', function(assert) {
      const t = buildTransform([
        tb.addRecord({ type: 'planet', id: 'jupiter', attributes: { name: 'Earth' } }),
        tb.removeRecord({ type: 'planet', id: 'jupiter' })
      ]);

      assert.deepEqual(getTransformRequests(source, t), []);
    });
开发者ID:SmuliS,项目名称:orbit.js,代码行数:8,代码来源:transform-requests-test.ts

示例4: module

module('ConnectionStrategy', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform(
    [t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
    null,
    'a'
  );
  const tB = buildTransform(
    [t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
    null,
    'b'
  );

  let strategy: ConnectionStrategy;
  let coordinator: Coordinator;
  let s1: any;
  let s2: any;

  hooks.beforeEach(function() {
    @pushable
    @updatable
    class MySource extends Source {}

    s1 = new MySource({ name: 's1' });
    s2 = new MySource({ name: 's2' });
  });

  test('can be instantiated', function(assert) {
    strategy = new ConnectionStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    assert.ok(strategy);
    assert.strictEqual(
      strategy.blocking,
      false,
      'blocking is false by default'
    );
    assert.equal(
      strategy.name,
      's1:update -> s2:push',
      'name is based on source names by default'
    );
  });

  test('assigns source and target when activated', async function(assert) {
    strategy = new ConnectionStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    await coordinator.activate();
    assert.strictEqual(strategy.source, s1, 'source is set');
    assert.strictEqual(strategy.target, s2, 'target is set');
  });

  test('installs listeners on activate and removes them on deactivate', async function(assert) {
    assert.expect(6);

    strategy = new ConnectionStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    assert.equal(
      s1.listeners('update').length,
      0,
      'no listeners installed yet'
    );
    assert.equal(
      s2.listeners('update').length,
      0,
      'no listeners installed yet'
    );

    await coordinator.activate();

    assert.equal(s1.listeners('update').length, 1, 'listeners installed');
    assert.equal(
      s2.listeners('update').length,
      0,
      'no listeners installed on target'
    );
//.........这里部分代码省略.........
开发者ID:orbitjs,项目名称:orbit.js,代码行数:101,代码来源:connection-strategy-test.ts

示例5: module

module('Coordinator', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform([t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })], null, 'a');
  const tB = buildTransform([t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })], null, 'b');
  const tC = buildTransform([t.addRecord({ type: 'planet', id: 'c', attributes: { name: 'c' } })], null, 'c');

  class MySource extends Source {}
  class MyStrategy extends Strategy {}

  let coordinator;

  test('can be instantiated', function(assert) {
    coordinator = new Coordinator();

    assert.ok(coordinator);
  });

  test('can add sources', function(assert) {
    let s1 = new MySource({ name: 's1' });
    let s2 = new MySource({ name: 's2' });
    let s3 = new MySource({ name: 's3' });

    coordinator = new Coordinator({ sources: [s1, s2] });
    assert.deepEqual(coordinator.sources, [s1, s2]);

    coordinator.addSource(s3);
    assert.deepEqual(coordinator.sources, [s1, s2, s3]);
    assert.deepEqual(coordinator.sourceNames, ['s1', 's2', 's3']);

    assert.strictEqual(coordinator.getSource('s1'), s1);
    assert.strictEqual(coordinator.getSource('s2'), s2);
    assert.strictEqual(coordinator.getSource('s3'), s3);
  });

  test('can not add a source without a name', function(assert) {
    let s1 = new MySource();
    coordinator = new Coordinator();

    assert.throws(
      () => {
        coordinator.addSource(s1);
      },
      new Error("Assertion failed: Sources require a 'name' to be added to a coordinator.")
    );
  });

  test('can not add a source with a duplicate name', function(assert) {
    let s1 = new MySource({ name: 's1' });
    let s2 = new MySource({ name: 's1' });
    coordinator = new Coordinator();

    assert.throws(
      () => {
        coordinator.addSource(s1);
        coordinator.addSource(s2);
      },
      new Error("Assertion failed: A source named 's1' has already been added to this coordinator.")
    );
  });

  test('can not add a source while activated', function(assert) {
    let s1 = new MySource({ name: 's1' });
    coordinator = new Coordinator();

    return coordinator.activate()
      .then(() => {
        assert.throws(
          () => {
            coordinator.addSource(s1);
          },
          new Error("Assertion failed: A coordinator's sources can not be changed while it is active.")
        );
      });
  });

  test('can not remove a source while activated', function(assert) {
    let s1 = new MySource({ name: 's1' });
    coordinator = new Coordinator({ sources: [s1] });

    return coordinator.activate()
      .then(() => {
        assert.throws(
          () => {
            coordinator.removeSource('s1');
          },
          new Error("Assertion failed: A coordinator's sources can not be changed while it is active.")
        );
      });
  });

  test('can not remove a source that has not been added', function(assert) {
    let s1 = new MySource({ name: 's1' });
    coordinator = new Coordinator();

    return coordinator.activate()
      .then(() => {
        assert.throws(
          () => {
            coordinator.removeSource('s1');
          },
//.........这里部分代码省略.........
开发者ID:SmuliS,项目名称:orbit.js,代码行数:101,代码来源:coordinator-test.ts

示例6: module

module('LogTruncationStrategy', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform([t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })], null, 'a');
  const tB = buildTransform([t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })], null, 'b');
  const tC = buildTransform([t.addRecord({ type: 'planet', id: 'c', attributes: { name: 'c' } })], null, 'c');
  const tD = buildTransform([t.addRecord({ type: 'planet', id: 'd', attributes: { name: 'd' } })], null, 'd');

  let logTruncationStrategy, coordinator, s1, s2, s3;

  hooks.beforeEach(function() {
    class MySource extends Source {}

    s1 = new MySource({ name: 's1' });
    s2 = new MySource({ name: 's2' });
    s3 = new MySource({ name: 's3' });
  });

  test('can be instantiated', function(assert) {
    logTruncationStrategy = new LogTruncationStrategy();

    assert.ok(logTruncationStrategy);
  });

  test('installs listeners on activate and removes them on deactivate', function(assert) {
    assert.expect(9);

    logTruncationStrategy = new LogTruncationStrategy();

    coordinator = new Coordinator({
      sources: [s1, s2, s3],
      strategies: [logTruncationStrategy]
    });

    assert.equal(s1.listeners('transform').length, 0, 'no listeners installed yet');
    assert.equal(s2.listeners('transform').length, 0, 'no listeners installed yet');
    assert.equal(s3.listeners('transform').length, 0, 'no listeners installed yet');

    return coordinator.activate()
      .then(() => {
        assert.equal(s1.listeners('transform').length, 1, 'listeners installed');
        assert.equal(s2.listeners('transform').length, 1, 'listeners installed');
        assert.equal(s3.listeners('transform').length, 1, 'listeners installed');

        return coordinator.deactivate();
      })
      .then(() => {
        assert.equal(s1.listeners('transform').length, 0, 'listeners removed');
        assert.equal(s2.listeners('transform').length, 0, 'listeners removed');
        assert.equal(s3.listeners('transform').length, 0, 'listeners removed');
      });
  });

  test('observes source transforms and truncates any common history up to the most recent match', function(assert) {
    assert.expect(3);

    logTruncationStrategy = new LogTruncationStrategy();

    coordinator = new Coordinator({
      sources: [s1, s2, s3],
      strategies: [logTruncationStrategy]
    });

    return coordinator.activate()
      .then(() => s1._transformed([tA, tB]))
      .then(() => s2._transformed([tA, tB]))
      .then(() => s3._transformed([tA, tB]))
      .then(() => {
        assert.ok(!s1.transformLog.contains('a'), 's1 has removed a');
        assert.ok(!s2.transformLog.contains('a'), 's2 has removed a');
        assert.ok(!s3.transformLog.contains('a'), 's3 has removed a');
     });
  });

  test('observes source transforms and truncates their history to after the most recent common entry', function(assert) {
    assert.expect(10);

    logTruncationStrategy = new LogTruncationStrategy();

    coordinator = new Coordinator({
      sources: [s1, s2, s3],
      strategies: [logTruncationStrategy]
    });

    return coordinator.activate()
      .then(() => all([
        s1._transformed([tA, tB, tC, tD]),
        s2._transformed([tA, tB, tC]),
        s3._transformed([tA, tB, tC])
      ]))
      .then(() => {
        assert.ok(!s1.transformLog.contains('a'), 's1 has removed a');
        assert.ok(!s2.transformLog.contains('a'), 's2 has removed a');
        assert.ok(!s3.transformLog.contains('a'), 's3 has removed a');

        assert.ok(!s1.transformLog.contains('b'), 's1 has removed b');
        assert.ok(!s2.transformLog.contains('b'), 's2 has removed b');
        assert.ok(!s3.transformLog.contains('b'), 's3 has removed b');

        assert.ok(s1.transformLog.contains('c'), 's1 contains c');
        assert.ok(s2.transformLog.contains('c'), 's2 contains c');
//.........这里部分代码省略.........
开发者ID:SmuliS,项目名称:orbit.js,代码行数:101,代码来源:log-truncation-strategy-test.ts

示例7: module

module('SyncStrategy', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform(
    [t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
    null,
    'a'
  );
  const tB = buildTransform(
    [t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
    null,
    'b'
  );

  let strategy: SyncStrategy;
  let coordinator: Coordinator;
  let s1: any;
  let s2: any;

  hooks.beforeEach(function() {
    @syncable
    class MySource extends Source {}

    s1 = new MySource({ name: 's1' });
    s2 = new MySource({ name: 's2' });
  });

  test('can be instantiated', function(assert) {
    strategy = new SyncStrategy({ source: 's1', target: 's2' });

    assert.ok(strategy);
    assert.strictEqual(
      strategy.blocking,
      false,
      'blocking is false by default'
    );
    assert.equal(
      strategy.name,
      's1:transform -> s2:sync',
      'name is based on source names by default'
    );
  });

  test('assigns source and target when activated', async function(assert) {
    strategy = new SyncStrategy({ source: 's1', target: 's2' });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    await coordinator.activate();

    assert.strictEqual(strategy.source, s1, 'source is set');
    assert.strictEqual(strategy.target, s2, 'target is set');
  });

  test('installs listeners on activate and removes them on deactivate', async function(assert) {
    assert.expect(6);

    strategy = new SyncStrategy({ source: 's1', target: 's2' });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    assert.equal(
      s1.listeners('transform').length,
      0,
      'no listeners installed yet'
    );
    assert.equal(
      s2.listeners('transform').length,
      0,
      'no listeners installed yet'
    );

    await coordinator.activate();

    assert.equal(s1.listeners('transform').length, 1, 'listeners installed');
    assert.equal(
      s2.listeners('transform').length,
      0,
      'no listeners installed on target'
    );

    await coordinator.deactivate();

    assert.equal(s1.listeners('transform').length, 0, 'listeners removed');
    assert.equal(
      s2.listeners('transform').length,
      0,
      'still no listeners on target'
    );
  });

  test('observes source `transform` event and invokes `sync` on target', async function(assert) {
    assert.expect(2);

    strategy = new SyncStrategy({ source: 's1', target: 's2' });
//.........这里部分代码省略.........
开发者ID:orbitjs,项目名称:orbit.js,代码行数:101,代码来源:sync-strategy-test.ts

示例8: module

module('RequestStrategy', function(hooks) {
  const t = new TransformBuilder();
  const tA = buildTransform(
    [t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
    null,
    'a'
  );
  const tB = buildTransform(
    [t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
    null,
    'b'
  );

  let strategy: RequestStrategy;
  let coordinator: Coordinator;
  let s1: any;
  let s2: any;

  hooks.beforeEach(function() {
    @pushable
    @updatable
    class MySource extends Source {}

    s1 = new MySource({ name: 's1' });
    s2 = new MySource({ name: 's2' });
  });

  test('can be instantiated', function(assert) {
    strategy = new RequestStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    assert.ok(strategy);
    assert.strictEqual(
      strategy.blocking,
      false,
      'blocking is false by default'
    );
    assert.equal(
      strategy.name,
      's1:update -> s2:push',
      'name is based on source names by default'
    );
  });

  test('assigns source and target when activated', async function(assert) {
    strategy = new RequestStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    await coordinator.activate();
    assert.strictEqual(strategy.source, s1, 'source is set');
    assert.strictEqual(strategy.target, s2, 'target is set');
  });

  test('installs listeners on activate and removes them on deactivate', async function(assert) {
    assert.expect(6);

    strategy = new RequestStrategy({
      source: 's1',
      target: 's2',
      on: 'update',
      action: 'push'
    });

    coordinator = new Coordinator({
      sources: [s1, s2],
      strategies: [strategy]
    });

    assert.equal(
      s1.listeners('update').length,
      0,
      'no listeners installed yet'
    );
    assert.equal(
      s2.listeners('update').length,
      0,
      'no listeners installed yet'
    );

    await coordinator.activate();

    assert.equal(s1.listeners('update').length, 1, 'listeners installed');
    assert.equal(
      s2.listeners('update').length,
      0,
      'no listeners installed on target'
    );
//.........这里部分代码省略.........
开发者ID:orbitjs,项目名称:orbit.js,代码行数:101,代码来源:request-strategy-test.ts


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