Skip to content

readEntityFrom()

Function

readEntityFrom<S, EntityType, IDType>(queryEntity: QueryEntity<S, EntityType, IDType>, id: IDType): Read<EntityType | undefined>

Create a new Read by selecting an entity from a QueryEntity using its id:

ts
const entity$: Read<EntityData | undefined> = readEntityFrom(queryEntity, entityId);

Source: akita-read/src/lib/read-entity-from.ts:20

Type parameters

ParameterDefaultDescription
S extends EntityState<any, any>-entity state used by the queryEntity
EntityTypegetEntityType<S>-
IDTypegetIDType<S>-

Parameters

ParameterTypeDescription
queryEntityQueryEntity<S, EntityType, IDType>QueryEntity to select from
idIDTypeentity id to select

Returns

Read<EntityType | undefined>

Returns a new Read that emits the selected entity or undefined if the entity does not exist

readEntityFrom<S, K, EntityType, IDType>( queryEntity: QueryEntity<S, EntityType, IDType>, id: IDType, key: K): Read<EntityType[K] | undefined>

Create a new Read by selecting an entity from a QueryEntity using its id and extracting the value using a given key:

ts
const name$: Read<string | undefined> = readEntityFrom(queryEntity, entityId, 'name');

Source: akita-read/src/lib/read-entity-from.ts:41

Type parameters

ParameterDefaultDescription
S extends EntityState<any, any>-entity state used by the queryEntity
K extends string | number | symbol-key of the entity
EntityTypegetEntityType<S>-
IDTypegetIDType<S>-

Parameters

ParameterTypeDescription
queryEntityQueryEntity<S, EntityType, IDType>QueryEntity to select from
idIDTypeentity id to select
keyKkey to extract from the entity

Returns

Read<EntityType[K] | undefined>

Returns a new Read that emits extracted value of the selected entity or undefined if the entity does not exist

readEntityFrom<S, R, EntityType, IDType>( queryEntity: QueryEntity<S, EntityType, IDType>, id: IDType, projection: Function): Read<R | undefined>

Create a new Read by selecting an entity from a QueryEntity using its id and extracting the value using a given projection:

ts
const name$: Read<string | undefined> = readEntityFrom(queryEntity, entityId, (entity) => entity.name);

Source: akita-read/src/lib/read-entity-from.ts:63

Type parameters

ParameterDefaultDescription
S extends EntityState<any, any>-entity state used by the queryEntity
R-returned type of the projection
EntityTypegetEntityType<S>-
IDTypegetIDType<S>-

Parameters

ParameterTypeDescription
queryEntityQueryEntity<S, EntityType, IDType>QueryEntity to select from
idIDTypeentity id to select
projection(entity?: EntityType) => Rprojection to pick from the entity

Returns

Read<R | undefined>

Returns a new Read that emits the result of the projection or undefined if the entity does not exist