select() and selectAll() don't have the same behavouir #744
Replies: 6 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
-
It doesn't make sense that |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
That is not clear for a consumer of the api. Akita should adhere to the principle of least suprise. Another "solution" would be to have select more strictly typed. Akita should know which store interface it is querying, so it should be able to typecheck that it exists. Ie, in pseudocode:
|
Beta Was this translation helpful? Give feedback.
-
@david-bulte found the issue. EntityState is defined as follows in the code: export interface EntityState<E = any, IDType = any> {
entities?: HashMap<E>;
ids?: IDType[];
loading?: boolean;
error?: any;
[key: string]: any;
} However, if we remove that [key:string]: any, select works as it should. See this stackblitz for a working example. I'm willing to start a PR where we remove the |
Beta Was this translation helpful? Give feedback.
-
I think using .select + .data should not be a valid use case anyway. .select seems to create a selection with parentNode being (the HTML root node) and .selectAll a selection with (after .select('body')). Appending the elements to html does not seem to be the expected behaviour, but it could be intentional. I'd ask the author, it could be a bug as well. |
Beta Was this translation helpful? Give feedback.
-
I'm submitting a...
Current behavior
select('selector')
starts at the root store.Example
select('foo')
on a store with pseudo-value:{ foo: 0, entities: [{ key: 'foo', value: 1 }] }
will return 0.However,
selectAll({limitTo: 1, filterBy: (entity) => entity.key=== 'foo'}).pipe(pluck('value')
will return 1.If you want the expected behavouir, you need to use
selectEntity
.Expected behavior
Either
select
should start at 'entity' level, orselectAll()
should be renamed toselectAllEntities()
to make it clear we are talking about entities.This makes it clear that code like
this.selectAll({limitTo: 1, filterBy: (entity) => entity.key=== 'foo'}).pipe(pluck('value')
cannot be simplified to this.select('foo').What is the motivation / use case for changing the behavior?
We had a real life bug because of this. The api is not clear.
Beta Was this translation helpful? Give feedback.
All reactions