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


TypeScript memory.update函數代碼示例

本文整理匯總了TypeScript中@orbit/memory.update函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript update函數的具體用法?TypeScript update怎麽用?TypeScript update使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了update函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

    test('Adding a record to the memory source immediately pushes the update to the remote', async function(assert) {
      assert.expect(1);

      await coordinator.activate();

      let planet: Record = {
        type: 'planet',
        id: schema.generateId(),
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      };

      fetchStub.withArgs('/planets').returns(
        jsonapiResponse(201, {
          data: {
            id: planet.id,
            type: 'planets',
            attributes: { name: 'Jupiter', classification: 'gas giant' }
          }
        })
      );

      await memory.update(t => t.addRecord(planet));

      let result = memory.cache.query(q => q.findRecord(planet));

      assert.deepEqual(result, {
        type: 'planet',
        id: planet.id,
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      });
    });
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:31,代碼來源:store-jsonapi-clientid-pessimistic-test.ts

示例2: update

 update(
   transformOrTransforms: TransformOrOperations,
   options?: object,
   id?: string
 ) {
   return this.source.update(transformOrTransforms, options, id);
 }
開發者ID:orbitjs,項目名稱:ember-orbit,代碼行數:7,代碼來源:store.ts

示例3: test

  test('Adding a record to the memory source queues an update request which will be pushed to the remote', async function(assert) {
    assert.expect(2);

    await coordinator.activate();

    fetchStub.withArgs('/planets').returns(
      jsonapiResponse(201, {
        data: {
          id: '12345',
          type: 'planets',
          attributes: { name: 'Jupiter', classification: 'gas giant' }
        }
      })
    );

    let planet: Record = {
      type: 'planet',
      id: schema.generateId(),
      attributes: { name: 'Jupiter', classification: 'gas giant' }
    };
    await memory.update(t => t.addRecord(planet));

    assert.deepEqual(
      memory.cache.query(q => q.findRecord(planet)),
      {
        type: 'planet',
        id: planet.id,
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      },
      'keys have not been syncd up yet - remote source still needs to process request'
    );

    await remote.requestQueue.process();

    assert.deepEqual(
      memory.cache.query(q => q.findRecord(planet)),
      {
        type: 'planet',
        id: planet.id,
        keys: { remoteId: '12345' },
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      },
      'keys are syncd up after remote source finishes processing requests'
    );
  });
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:45,代碼來源:store-jsonapi-remoteid-optimistic-test.ts

示例4: test

    test('Adding a record to the memory source immediately pushes the update to the remote', async function(assert) {
      assert.expect(3);

      await coordinator.activate();

      fetchStub.withArgs('/planets').returns(
        jsonapiResponse(201, {
          data: {
            id: '12345',
            type: 'planets',
            attributes: { name: 'Jupiter', classification: 'gas giant' }
          }
        })
      );

      let planet: Record = {
        type: 'planet',
        id: schema.generateId(),
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      };
      await memory.update(t => t.addRecord(planet));

      let result = memory.cache.query(q => q.findRecord(planet));

      assert.deepEqual(result, {
        type: 'planet',
        id: planet.id,
        keys: { remoteId: '12345' },
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      });

      assert.equal(
        keyMap.idToKey('planet', 'remoteId', planet.id),
        '12345',
        'id mapped to key'
      );
      assert.equal(
        keyMap.keyToId('planet', 'remoteId', '12345'),
        planet.id,
        'key mapped to id'
      );
    });
開發者ID:orbitjs,項目名稱:orbit.js,代碼行數:42,代碼來源:store-jsonapi-remoteid-pessimistic-test.ts


注:本文中的@orbit/memory.update函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。