observeEntity

abstract fun <T : Any> observeEntity(clazz: KClass<T>, id: String): Flow<T?>

Observes a single entity of type T by its id, emitting the updated entity on changes.

Return

A Flow emitting the entity or null if not found.

Example:

storage.observeEntity(SampleUserProfile::class, "u1").collect { /* react */}

Parameters

clazz

The KClass of the entity type.

id

The unique identifier of the entity.

Type Parameters

T

The entity type (must be annotated with @Entity).