angular-architects / ngrx-toolkit

Various Extensions for the NgRx Signal Store
MIT License
146 stars 22 forks source link

WithRedux Unable to execute multiple effects for action #33

Closed Chudroy closed 5 months ago

Chudroy commented 5 months ago

Using WithRedux, I have three effects. The first effect dispatches an action. The other two effects are listening for this action. Only the third effect fires, the second one doesn't. If i remove the third effect, the second one fires. It seems only one effect can listen for an action at a time.

Proposed fix: make it like original ngrx store, multiple effects can listen for an action.

        loadInstallationDetail$: create(actions.loadInstallationDetail).pipe(
          switchMap(({ installationId }) => {
            return installationsService.getInstallation(installationId).pipe(
              tapResponse(
                (installation) => {
                  actions.loadInstallationDetailSuccess({
                    installation,
                  });
                },
                (error: HttpErrorResponse) => {
                  httpErrorSnackbarService.showHttpErrorSnackbar(error);
                },
              ),
            );
          }),
        ),
        loadInstallationDetailSuccess$: create(
          actions.loadInstallationDetailSuccess,
        ).pipe(
          tap(({ installation }) => {
            const title = installation?.name;
            const id = installation?.id.toString();
            if (id && title) {
              globalStore.dispatch(
                LayoutStateActions.setLayoutState({
                  id,
                  entityType: 'installation',
                  title,
                }),
              );
            }
          }),
        ),
        loadInstallationCampaigns$: create(
          actions.loadInstallationDetailSuccess,
        ).pipe(
          switchMap(({ installation }) => {
            return installationsService
              .getInstallationCampaigns(installation?.id?.toString())
              .pipe(
                tapResponse(
                  (campaigns) => {
                    return actions.loadInstallationCampaignsSuccess({
                      campaigns: campaigns || [],
                    });
                  },
                  (error: HttpErrorResponse) => {
                    httpErrorSnackbarService.showHttpErrorSnackbar(error);
                  },
                ),
              );
          }),
        ),

the second effect, loadInstallationDetailSuccess$ doesn't fire. the effect loadInstallationCampaigns$ does however. This seems to me that the create function is overwriting the subscription to the action `actions.loadInstallationDetailSuccess of the second effect with the third effect's subscription to the same action.

rainerhahnekamp commented 5 months ago

Thanks for the info. Fix will follow

rainerhahnekamp commented 5 months ago

Has been fixed in version 0.3.0