akita
akita copied to clipboard
Setting QuertyConfig on base query doesn't apply to UI or sub queries
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[x] Other... Please describe:
Current behavior
Setting a query config does not affect the UI query or any sub queries
@QueryConfig({
sortBy: 'id',
sortByOrder: Order.ASC
})
There doesn't seem to be an obvious or documented way to set the default queryconfig for ui and sub queries. Is that possible, without creating a new class for each one?
Expected behavior
QueryConfig object should have a flag on whether this sort object should descend to substores or not.
In addition, it would be nice if this query function could actually sort the store itself, rather than getting the store and resorting every time.
Motivation: The reason being that currently, the unsorted state renders in my UI for a half second before the state is sorted thereby rerendering the UI, which looks bad. Is there a way to sort the actual state, besides sorting and overwriting with a new state entirely?
@QueryConfig({
sortBy: 'id',
sortByOrder: Order.ASC
})
export class DeviceTelemetryQuery extends QueryEntity<DeviceTelemetryState> {
ui: EntityUIQuery<State>;
constructor(protected store: DeviceTelemetryStore) {
super(store);
this.createUIQuery();
}
}
Environment
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: v12.18.1
- Platform: Windows
The UI query points to a different store. You're welcome to create a PR that passes the query config to createUIQuery.
https://github.com/datorama/akita/blob/888a8253ed03d8af77306d06e0ecbef3b1b78cec/libs/akita/src/lib/queryEntity.ts#L381
Hey, ok thanks. I will see about making that happen.
Also I was thinking alternatively to passing the query config to the createUIQuery as an option on the query config (or as another way of doing it), what do you think about adding a param to the createUIQuery method that accepts the same params as the queryConfig?
this.createUIQuery({
sortBy: 'id',
sortByOrder: Order.ASC
})
Any preference one way or the other?
This one:
const config = {
sortBy: 'id',
sortByOrder: Order.ASC
}
@QueryConfig(config)
export class DeviceTelemetryQuery extends QueryEntity<DeviceTelemetryState> {
ui: EntityUIQuery<State>;
constructor(protected store: DeviceTelemetryStore) {
super(store);
this.createUIQuery(config);
}
}