v0.11 Queries, Queryable, and useQuery
Besides the performance and data integrity benefits of normalizing the state, we get the added benefit of being able to safely access and query the store directly.
In this release we tune and simplify this functionality by unifying around the concepts of Querable Schemas. These include Entity, All, Collection, Query, and Union
The biggest impact of this change is the introduction of a new hook useQuery(), which allows direct store lookups using the Querable Schemas.
class User extends Entity {
username = '';
id = '';
groupId = '';
pk() {
return this.id;
}
static index = ['username' as const];
}
const bob = useQuery(User, { username: 'bob' });
const bob = useQuery(User, { id: '5' });
Similarly, we can lookup Querables with controller and snapshot using the controller.get
const bob = snapshot.get(User, { username: 'bob' });
Additionally, we have invested in further performance improvements, resulting in around a 2x performance increase for most operations and Queries being 16x faster.
Breaking Changes:
- useCache(new Index(MyEntity)) -> useQuery(MyEntity)
- new Query -> new schema.Query
- useCache(myQuery) -> useQuery(myQuery)
- new AbortOptimistic() -> snapshot.abort
- Entity.useIncoming → Entity.shouldUpdate
- useCache() accepts Endpoints with sideEffects (like Resource.update)
- Allow Entity.pk() to return numbers.
- 2-16x performance improvements