DataProvider - guiled/LRE GitHub Wiki

Data Provider

Description

Date providers are one of the major feature of LRE. This structure provides a way to handle data easily with some methods. Some entities are directly Data Providers (which is mentioned in their documentation), some others provide method that returns a Data Provider.

You can consider Data Provider like a empowered Let's Role Table : it has rows and columns. Each row has an id.

Some data providers

LRE automatically add the Data Provider features to the following entities :

  • Tables
  • Groups

The following components have methods that return a Data Provider

  • Repeater
  • MultiChoice
  • Container

Methods

providedValue

This method is the central one for Data Providers but you'll probably never use it explicitly. However you must know it in order to understand all the other methods. providedValue returns the up-to-date data of the Data Provider, in a useable form : an js object whose keys are the data id, and values are the row data.

Take this example, showing the "races" Table content:

+-----------+----------+-------+-----------------------------+
| id        | name     | bonus | description                 |
+-----------+----------+-------+-----------------------------+
| "human"   | Human    | +1    | Versatile and adaptable     |
| "elf"     | Elf      | +2    | Agile and attuned to nature |
| "dwarf"   | Dwarf    | +3    | Sturdy and resilient        |
| "orc"     | Orc      | +2    | Strong and fierce           |
| "halfling"| Halfling | +1    | Small and stealthy          |
+-----------+----------+-------+-----------------------------+

The following code shows you the kind of data that providedValue() returns.

  const races = Tables.get("races");
  log(races.providedValue());
  // Output:
  // {
  //   "human": { "id": "human", "name": "Human", "bonus": "+1", "description": "Versatile and adaptable" },
  //   "elf": { "id": "elf", "name": "Elf", "bonus": "+2", "description": "Agile and attuned to nature" },
  //   "dwarf": { "id": "dwarf", "name": "Dwarf", "bonus": "+3", "description": "Sturdy and resilient" },
  //   "orc": { "id": "orc", "name": "Orc", "bonus": "+2", "description": "Strong and fierce" },
  //   "halfling": { "id": "halfling", "name": "Halfling", "bonus": "+1", "description": "Small and stealthy" }
  // }

select(column: string): DataProvider

select returns a DataProvider whose providedValue lines will contain only the column identified by the arg. This kind of code can be directly used for setting choices in a Choice

const raceNames = races.select("name");
log(raceNames.providedValue());
// Output:
// {
//   "human": { "id": "human", "name": "Human" },
//   "elf": { "id": "elf", "name": "Elf" },
//   "dwarf": { "id": "dwarf", "name": "Dwarf" },
//   "orc": { "id": "orc", "name": "Orc" },
//   "halfling": { "id": "halfling", "name": "Halfling" }
// }
sheet.get("raceChoice").setChoices(raceNames);

sort and sortBy

each

filter

where

transform

count or length

countDistinct

singleValue

singleId

min and max

sum

limit

getBy

toArray

search

union

innerJoin and leftJoin

getData

refresh