本文整理匯總了TypeScript中@orbit/data.KeyMap.keyToId方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript KeyMap.keyToId方法的具體用法?TypeScript KeyMap.keyToId怎麽用?TypeScript KeyMap.keyToId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@orbit/data.KeyMap
的用法示例。
在下文中一共展示了KeyMap.keyToId方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('#push - replaceKey - when base record does not exist', async function(assert) {
assert.expect(2);
let revised: Record = {
type: 'planet',
id: 'jupiter',
keys: {
remoteId: '123'
}
};
await source.push(t =>
t.replaceKey({ type: 'planet', id: 'jupiter' }, 'remoteId', '123')
);
assert.deepEqual(
await getRecordFromIndexedDB(source.cache, revised),
revised,
'indexeddb contains record'
);
assert.equal(
keyMap.keyToId('planet', 'remoteId', '123'),
'jupiter',
'key has been mapped'
);
});
示例2: test
test('#patch sets data and #records retrieves it', function(assert) {
assert.expect(4);
let cache = new MemoryCache({ schema, keyMap });
const earth: Record = {
type: 'planet',
id: '1',
attributes: { name: 'Earth' },
keys: { remoteId: 'a' }
};
cache.on('patch', (operation, data) => {
assert.deepEqual(operation, {
op: 'addRecord',
record: earth
});
assert.deepEqual(data, earth);
});
cache.patch(t => t.addRecord(earth));
assert.strictEqual(
cache.getRecordSync({ type: 'planet', id: '1' }),
earth,
'objects strictly match'
);
assert.equal(
keyMap.keyToId('planet', 'remoteId', 'a'),
'1',
'key has been mapped'
);
});
示例3:
.then(() => {
assert.equal(
keyMap.keyToId('planet', 'remoteId', 'p2'),
'jupiter',
'key has been mapped'
);
});
示例4: test
test('#query - a specific record', async function(assert) {
assert.expect(2);
let earth: Record = {
type: 'planet',
id: 'earth',
attributes: {
name: 'Earth',
classification: 'terrestrial'
}
};
let jupiter: Record = {
type: 'planet',
id: 'jupiter',
keys: {
remoteId: 'p2'
},
attributes: {
name: 'Jupiter',
classification: 'gas giant'
}
};
let io: Record = {
type: 'moon',
id: 'io',
attributes: {
name: 'Io'
}
};
await cache.patch(t => [
t.addRecord(earth),
t.addRecord(jupiter),
t.addRecord(io)
]);
// reset keyMap to verify that pulling records also adds keys
keyMap.reset();
let record = await cache.query(q => q.findRecord(jupiter));
assert.deepEqual(record, jupiter, 'query results are expected');
assert.equal(
keyMap.keyToId('planet', 'remoteId', 'p2'),
'jupiter',
'key has been mapped'
);
});
示例5: 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'
);
});
示例6: test
test('#patch can replace records', function(assert) {
assert.expect(4);
let cache = new Cache({ schema, keyMap });
const earth = { type: 'planet', id: '1', attributes: { name: 'Earth' }, keys: { remoteId: 'a' } };
cache.on('patch', (operation, data) => {
assert.deepEqual(operation, {
op: 'replaceRecord',
record: earth
});
assert.deepEqual(data, earth);
});
cache.patch(t => t.replaceRecord(earth));
assert.strictEqual(cache.records('planet').get('1'), earth, 'objects strictly match');
assert.equal(keyMap.keyToId('planet', 'remoteId', 'a'), '1', 'key has been mapped');
});