forEachResultCell
The forEachResultCell method takes a function that it will then call for each ResultCell in the ResultRow of a query.
forEachResultCell(
queryId: string,
rowId: string,
cellCallback: ResultCellCallback,
): void| Type | Description | |
|---|---|---|
queryId | string | The |
rowId | string | The |
cellCallback | ResultCellCallback | The function that should be called for every |
| returns | void | This has no return value. |
This method is useful for iterating over each ResultCell of the ResultRow of the query in a functional style. The cellCallback parameter is a ResultCellCallback function that will be called with the Id and value of each ResultCell.
Example
This example iterates over each ResultCell in a query's ResultRow.
import {createQueries, createStore} from 'tinybase';
const store = createStore().setTable('pets', {
fido: {species: 'dog', color: 'brown'},
felix: {species: 'cat', color: 'black'},
cujo: {species: 'dog', color: 'black'},
});
const queries = createQueries(store).setQueryDefinition(
'dogColors',
'pets',
({select, where}) => {
select('species');
select('color');
where('species', 'dog');
},
);
queries.forEachResultCell('dogColors', 'fido', (cellId, cell) => {
console.log(`${cellId}: ${cell}`);
});
// -> 'species: dog'
// -> 'color: brown'
Since
v2.0.0