How do i can use concatLastestFrom?

118 Views Asked by At

I am try use effects with my store, but 2 days i have this error: enter image description here Idk why it happened, can u help me please?

stackblitz simulation

Action:

export const LoadMeetings = createAction('[ Meetings/Api ] Load Meetings');

Effect:

    readonly loadMeetings$ = createEffect(() =>
        this.actions$.pipe(
            ofType(fromMeetingsActions.LoadMeetings),
            concatLatestFrom(action => this.store.select(fromMeetings.selectMeetingsState)),
        )
    );

Selector:

export const selectMeetingsState =
    createFeatureSelector<MeetingsStateModel>(meetingsFeatureKey);
//This doesn't work too
const selector = <T>(mapping: (state: MeetingsStateModel) => T) => createSelector(selectMeetingsState, mapping);
export const selectSelectedMeetingId = selector((state) => state.selectedMeetingId);

I try find answer in google, docs, youtube, q&a and any services, but zero feed back.. I try change operator map, concatMap, switchMap, pipe and another.. I try change selectors, but zero result

1

There are 1 best solutions below

2
wlf On BEST ANSWER

Effects usually map to an action ie:

readonly loadMeetings$ = createEffect(() =>
  this.actions$.pipe(
    ofType(fromMeetingsActions.LoadMeetings),
    concatLatestFrom(action => this.store.select(fromMeetings.selectMeetingsState)),
    map(() => fromMeetings.loadMeetingsSucceeded)
    ), 
);

Stackblitz: https://stackblitz.com/edit/angular-pq8vlw?file=src%2Fmeetings%2F%2Bstate%2Feffects.ts

If they don't return an action you need to add { dispatch: false }:

readonly loadMeetings$ = createEffect(() =>
   this.actions$.pipe(
     ofType(fromMeetingsActions.LoadMeetings),
     concatLatestFrom((action) =>
        this.store.select(fromMeetings.selectMeetingsState)
     )
   ),
   { dispatch: false }
);

Stackblitz: https://stackblitz.com/edit/angular-h2yifk?file=src%2Fmeetings%2F%2Bstate%2Feffects.ts