Impossible to use selectAll from @ngrx/entity inside a createSelector
It seems the selectAll @ngrx/entity adapter selector doesn't behave properly when inserted in a createSelector where its result is used.
Minimal reproduction of the bug/regression with instructions:
https://stackblitz.com/edit/angular-testing-template-1tgjra?file=app%2Fchannel.reducer.ts
As you can see here in the tests,
export const getAllChannels = createSelector(
selectAll
);
gives the expected Channel[]
But as soon as we use the result, then it breaks. For example:
export const getChannelsAfterSelectAll = createSelector(
getAllChannels,
(channels: Channel[]) => channels
);
returns not only the expected Channel[] but the whole state part.
it's tested through:
describe('getChannelsAfterSelectAll', () => {
it('should return proper section of state', () => {
expect(getChannelsAfterSelectAll.projector(CHANNEL_STATE)).toEqual(CHANNELS);
});
});
and produces the following error in the tests:
expected { loading: true, loaded: true, lastLoaded: 1538322993015, ids: [ 'id1', 'id2' ], entities: Object({ id1: Channel({ id: 'id1', name: 'Channel 1', single: true }), id2: Channel({ id: 'id2', name: 'Channel 2', single: false }) }) }) to equal [ Channel({ id: 'id1', name: 'Channel 1', single: true }), Channel({ id: 'id2', name: 'Channel 2', single: false }) ]
Of course, then, trying to use the array breaks:
export const getMultiRecipientChannels = createSelector(
getAllChannels,
(channels: Channel[]) => channels.filter((channel: Channel) => !channel.single)
);
channels.filter is not a function
Expected behavior:
We should be able to use selectAll result within a createSelector and obtain the proper result from this @ngrx/entity adapter selector.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
Angular 6 Ngrx 6.1.0 All browsers and tests engine (jasmine, jest)
@blackholegalaxy what is the solution to this problem?
@glennverschooren @blackholegalaxy Facing the same issue. Any solution?
Angular 10 here
"@angular/core": "~10.2.4",
...
"@ngrx/effects": "10.1.2",
"@ngrx/entity": "10.1.2",
"@ngrx/router-store": "10.1.2",
"@ngrx/store": "10.1.2",
"@ngrx/store-devtools": "10.1.2"
Why is this issue closed? @blackholegalaxy what's the fix? Obviously the selectors are not working