readFrom()
Function
readFrom<T>(target:
Query<T> |BehaviorSubject<T>):Read<T>
Create a new Read containing the whole state of the Store using a Query or reading the state of a BehaviorSubject:
const state$: Read\<StoreState\> = readFrom(query);
const subjectState$: Read\<string\> = readFrom(behaviorSubject);Source: akita-read/src/lib/read-from.ts:21
Type parameters
| Parameter | Description |
|---|---|
| T | state used by the target |
Parameters
| Parameter | Type | Description |
|---|---|---|
| target | Query<T> | BehaviorSubject<T> | Query or BehaviorSubject to select from |
Returns
Read<T>
Returns a new Read that emits the state of the Query or BehaviorSubject
Create a new Read by selecting a key from the Store using a Query:
const date$: Read\<Date\> = readFrom(query, 'date');Source: akita-read/src/lib/read-from.ts:36
Type parameters
| Parameter | Description |
|---|---|
| T | state used by the query |
K extends string | number | symbol | key of the state |
Parameters
| Parameter | Type | Description |
|---|---|---|
| query | Query<T> | Query to select from |
| key | K | key to select from the state |
Returns
Read<T[K]>
Returns a new Read that emits the value of the selected field of the state
readFrom<T, P>(query:
Query<T>, projection:Function):Read<P>
Create a new Read using a projection from the Store using a Query:
const date$: Read\<Date\> = readFrom(query, state => state.date);⚠️ Avoid doing heavy calculations inside the projection. ⚠️
> The result of the projection is automatically piped through a distinctUntilChanged > operator to avoid unnecessary recalculations/emissions. > ```ts
const sum$: Read<number> = readFrom(query, state => state.prices.reduce((sum, curr) => sum + curr, 0));
\> By doing this calculation inside the projection, this calculation is always redone when the state changes, \> even though the prices did not change at all.
Source: akita-read/src/lib/read-from.ts:61
Type parameters
| Parameter | Description |
|---|---|
| T | state used by the query |
| P | return type of the projection |
Parameters
| Parameter | Type | Description |
|---|---|---|
| query | Query<T> | Query to select from |
| projection | (state: T) => P | projection to pick from the state |
Returns
Read<P>
Returns a new Read that emits the value returned by the projection
readFrom<T, K>(query:
Query<T>, keys: readonlyK[]):Read<Pick<T,K>>
Create a new Read by selecting a list of keys from the Store using a Query:
const data$: Read\<{date: Date, count: number}\> = readFrom(query, ['date', 'count']);Source: akita-read/src/lib/read-from.ts:76
Type parameters
| Parameter | Description |
|---|---|
| T | state used by the query |
K extends string | number | symbol | key of the state |
Parameters
| Parameter | Type | Description |
|---|---|---|
| query | Query<T> | Query to select from |
| keys | readonly K[] | array of keys to select from the state |
Returns
Read<Pick<T, K>>
Returns a new Read that emits an object containing the values selected by the keys