TinyBase logoTinyBase

forEachResultCell

The forEachResultCell method takes a function that it will then call for each ResultCell in the ResultRow of a query.

forEachResultCell(
  queryId: Id,
  rowId: Id,
  cellCallback: ResultCellCallback,
): void
TypeDescription
queryIdId

The Id of a query.

rowIdId

The Id of a ResultRow in the query's ResultTable.

cellCallbackResultCellCallback

The function that should be called for every ResultCell of the query's ResultRow.

returnsvoid

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.

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