james Makinde
james Makinde

Reputation: 983

NgRx selector not updating when store changes

I have different selectors in my applications but for some reason this particular selector does not update when a change is made to my store, and I have no idea why. The code for the line with selectDataStream is never ran after the first time, subsequent store changes and nothing happens. I see my new value is updated in the store.

Component:

   ngAfterViewInit(): void {
        if (this.fields && this.fields.length > 0) {
            this.store$.select<any[]>(getConnections(this.connectorId))
                .takeUntil(this.onDestroy$).subscribe(connections => {
                    this.selectDataStream.next(connections);
                    this.cdRef.detectChanges();
                });
        }
    }

Reducer code:

const model = state.connectionresults[connectionId];

            const updatedstate = {
                ...state,
                connectionresults: {
                    ...state.connectionresults,
                    [connectionId]: {
                        ...model,
                        connections: [...payload]
                    }
                }               
            };

            return {
                ...updatedstate
            };

Selector:

 export const selectConnectionResults = createSelector(
    selectFinderData,
    (state: FinderState) => state.connectionresults
);

     export const getConnections = (id) => createSelector(selectConnectionResults, entities => {
        return entities[id];
    });

What am I doing wrong that's preventing the selector from firing?

Upvotes: 0

Views: 7374

Answers (1)

james Makinde
james Makinde

Reputation: 983

Found the issue. I was updating a wrong property in my store, and selecting from a different value. :-)

Upvotes: 5

Related Questions