Dispatch multiple action from one effectDispatch multiple action and wait completion to send nextngrx ofType, @ngrx/effectshow to return the value from effect [NGRX] to component?ngrx effect dispatch action error and null when passing action payloadNgRx Success Action not DispatchedHow propagate action.payload from Action in ngrx-effect to catchError or map operator?Effect “AuthEffects.register$” dispatched an invalid actionNGRX action is dispatched but effect is not firingHow to pass params (action.payload) to service in ngrx/effects ?How to dispatch multiple actions from ngrx 7 effects

How soon after takeoff can you recline your airplane seat?

How to find out who created an event?

Why will we fail creating a self sustaining off world colony?

Grid: different background color (of row) based on values

Hard for me to understand one tip written in "The as-if rule" of cppreference

Why are examinees often not allowed to leave during the start and end of an exam?

Why was Pan Am Flight 103 flying over Lockerbie?

What does 'in attendance' mean on an England death certificate?

Why should I allow multiple IPs on a website for a single session?

What prevents a US state from colonizing a smaller state?

The alcoholic village festival

Did the Russian Empire have a claim to Sweden? Was there ever a time where they could have pursued it?

German idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)

How can an inexperienced GM keep a game fun for experienced players?

Avoiding repetition when using the "snprintf idiom" to write text

How to count the number of bytes in a file, grouping the same bytes?

Is it advisable to inform the CEO about his brother accessing his office?

Fully submerged water bath for stove top baking?

Early 2000s movie about time travel, protagonist travels back to save girlfriend, then into multiple points in future

Having to constantly redo everything because I don't know how to do it

"I am [the / an] owner of a bookstore"?

How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?

How useful would a hydroelectric power plant be in the post-apocalypse world?

Why do some PCBs have exposed plated perimeters?



Dispatch multiple action from one effect


Dispatch multiple action and wait completion to send nextngrx ofType, @ngrx/effectshow to return the value from effect [NGRX] to component?ngrx effect dispatch action error and null when passing action payloadNgRx Success Action not DispatchedHow propagate action.payload from Action in ngrx-effect to catchError or map operator?Effect “AuthEffects.register$” dispatched an invalid actionNGRX action is dispatched but effect is not firingHow to pass params (action.payload) to service in ngrx/effects ?How to dispatch multiple actions from ngrx 7 effects













0















Hi I want dispatch my new action "LoadConfig" in "loadFullService$" effect.



How to do ?



 @Effect()
loadFullService$: Observable<Action> = this.actions$
.ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
.switchMap(action =>
return this.apiService
.loadFullService(action.payload)
.map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
.catch(error => of(new servicesActions.LoadFailureAction(error)));
)
;

@Effect()
loadConfig$: Observable<Action> = this.actions$
.ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
.switchMap(action =>
console.log("action config", action);
return this.apiService
.loadConfig(action.id, action.name)
.map((config: Configuration) => new servicesActions.LoadConfigSuccess(config))
.catch(error => of(new servicesActions.LoadConfigFailure(error)));
);


Thx u










share|improve this question


























    0















    Hi I want dispatch my new action "LoadConfig" in "loadFullService$" effect.



    How to do ?



     @Effect()
    loadFullService$: Observable<Action> = this.actions$
    .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
    .switchMap(action =>
    return this.apiService
    .loadFullService(action.payload)
    .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
    .catch(error => of(new servicesActions.LoadFailureAction(error)));
    )
    ;

    @Effect()
    loadConfig$: Observable<Action> = this.actions$
    .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
    .switchMap(action =>
    console.log("action config", action);
    return this.apiService
    .loadConfig(action.id, action.name)
    .map((config: Configuration) => new servicesActions.LoadConfigSuccess(config))
    .catch(error => of(new servicesActions.LoadConfigFailure(error)));
    );


    Thx u










    share|improve this question
























      0












      0








      0


      1






      Hi I want dispatch my new action "LoadConfig" in "loadFullService$" effect.



      How to do ?



       @Effect()
      loadFullService$: Observable<Action> = this.actions$
      .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
      .switchMap(action =>
      return this.apiService
      .loadFullService(action.payload)
      .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
      .catch(error => of(new servicesActions.LoadFailureAction(error)));
      )
      ;

      @Effect()
      loadConfig$: Observable<Action> = this.actions$
      .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
      .switchMap(action =>
      console.log("action config", action);
      return this.apiService
      .loadConfig(action.id, action.name)
      .map((config: Configuration) => new servicesActions.LoadConfigSuccess(config))
      .catch(error => of(new servicesActions.LoadConfigFailure(error)));
      );


      Thx u










      share|improve this question














      Hi I want dispatch my new action "LoadConfig" in "loadFullService$" effect.



      How to do ?



       @Effect()
      loadFullService$: Observable<Action> = this.actions$
      .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
      .switchMap(action =>
      return this.apiService
      .loadFullService(action.payload)
      .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
      .catch(error => of(new servicesActions.LoadFailureAction(error)));
      )
      ;

      @Effect()
      loadConfig$: Observable<Action> = this.actions$
      .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
      .switchMap(action =>
      console.log("action config", action);
      return this.apiService
      .loadConfig(action.id, action.name)
      .map((config: Configuration) => new servicesActions.LoadConfigSuccess(config))
      .catch(error => of(new servicesActions.LoadConfigFailure(error)));
      );


      Thx u







      angular ngrx ngrx-store ngrx-effects






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 29 '17 at 13:43









      Matthis.hMatthis.h

      1321 silver badge13 bronze badges




      1321 silver badge13 bronze badges




















          2 Answers
          2






          active

          oldest

          votes


















          1














          Import the Store service in the constructor.



          constructor(
          private store: Store<StoreType>,
          )


          Then inside the action call this.store.dispatch(newAction), with a do operator (usual), anywhere after the ofType().






          @Effect()
          loadFullService$: Observable<Action> = this.actions$
          .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
          .do(action =>
          this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
          )
          .switchMap(action =>
          return this.apiService
          .loadFullService(action.payload)
          .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
          .catch(error => of(new servicesActions.LoadFailureAction(error)));
          );





          Another general approach, which I used to like, is creating a new observable:






          @Effect()
          loadFullService$: Observable<Action> = this.actions$
          .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
          .switchMap(action =>
          return this.apiService
          .loadFullService(action.payload)
          .mergeMap((service: Service) =>
          return new Observable(observer =>
          const successAction = new servicesActions.LoadFullServiceSuccess(service));
          const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
          observer.next(successAction);
          observer.next(newAction);
          observer.complete();
          );
          )
          .catch(error => of(new servicesActions.LoadFailureAction(error)));
          );





          The downside is that it adds more churn and following the code gets a bit harder sometimes.



          Finally, a third approach:






          @Effect()
          loadFullService$: Observable<Action> = this.actions$
          .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
          .switchMap(action =>
          return this.apiService
          .loadFullService(action.payload)
          .mergeMap((service: Service) =>
          const successAction = new servicesActions.LoadFullServiceSuccess(service));
          const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
          return Observable.from([successAction, newAction]);
          )
          .catch(error => of(new servicesActions.LoadFailureAction(error)));
          );








          share|improve this answer

























          • I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

            – Matthis.h
            Nov 29 '17 at 13:56











          • Yes, I updated the answer

            – André Werlang
            Nov 29 '17 at 14:09











          • Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

            – Matthis.h
            Nov 29 '17 at 14:20











          • action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

            – André Werlang
            Nov 29 '17 at 14:26











          • it may be at action.name instead, given you're using classes.

            – André Werlang
            Nov 29 '17 at 14:27



















          0














          Effects aren't functions that take one element. They are stream transformations, and you can use all the power of RxJS here. For example, to get what you asked for in the title:



          @Effect()
          loadConfig$: Observable<Action> = this.actions$
          .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
          .switchMap(action => Observable.of(
          new OtherAction(),
          new OtherAction2(),
          );


          Note: this is quite similar to 3rd version in the André's answer.






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47554267%2fdispatch-multiple-action-from-one-effect%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Import the Store service in the constructor.



            constructor(
            private store: Store<StoreType>,
            )


            Then inside the action call this.store.dispatch(newAction), with a do operator (usual), anywhere after the ofType().






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            Another general approach, which I used to like, is creating a new observable:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            The downside is that it adds more churn and following the code gets a bit harder sometimes.



            Finally, a third approach:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );








            share|improve this answer

























            • I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

              – Matthis.h
              Nov 29 '17 at 13:56











            • Yes, I updated the answer

              – André Werlang
              Nov 29 '17 at 14:09











            • Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

              – Matthis.h
              Nov 29 '17 at 14:20











            • action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

              – André Werlang
              Nov 29 '17 at 14:26











            • it may be at action.name instead, given you're using classes.

              – André Werlang
              Nov 29 '17 at 14:27
















            1














            Import the Store service in the constructor.



            constructor(
            private store: Store<StoreType>,
            )


            Then inside the action call this.store.dispatch(newAction), with a do operator (usual), anywhere after the ofType().






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            Another general approach, which I used to like, is creating a new observable:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            The downside is that it adds more churn and following the code gets a bit harder sometimes.



            Finally, a third approach:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );








            share|improve this answer

























            • I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

              – Matthis.h
              Nov 29 '17 at 13:56











            • Yes, I updated the answer

              – André Werlang
              Nov 29 '17 at 14:09











            • Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

              – Matthis.h
              Nov 29 '17 at 14:20











            • action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

              – André Werlang
              Nov 29 '17 at 14:26











            • it may be at action.name instead, given you're using classes.

              – André Werlang
              Nov 29 '17 at 14:27














            1












            1








            1







            Import the Store service in the constructor.



            constructor(
            private store: Store<StoreType>,
            )


            Then inside the action call this.store.dispatch(newAction), with a do operator (usual), anywhere after the ofType().






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            Another general approach, which I used to like, is creating a new observable:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            The downside is that it adds more churn and following the code gets a bit harder sometimes.



            Finally, a third approach:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );








            share|improve this answer















            Import the Store service in the constructor.



            constructor(
            private store: Store<StoreType>,
            )


            Then inside the action call this.store.dispatch(newAction), with a do operator (usual), anywhere after the ofType().






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            Another general approach, which I used to like, is creating a new observable:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            The downside is that it adds more churn and following the code gets a bit harder sometimes.



            Finally, a third approach:






            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );








            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .do(action =>
            this.store.dispatch(new servicesActions.LoadConfig(action.payload.id, action.payload.name))
            )
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .map((service: Service) => new servicesActions.LoadFullServiceSuccess(service))
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            return new Observable(observer =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            observer.next(successAction);
            observer.next(newAction);
            observer.complete();
            );
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );





            @Effect()
            loadFullService$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadFullService>(servicesActions.LOAD_FULL_SERVICE)
            .switchMap(action =>
            return this.apiService
            .loadFullService(action.payload)
            .mergeMap((service: Service) =>
            const successAction = new servicesActions.LoadFullServiceSuccess(service));
            const newAction = new servicesActions.LoadConfig(action.id, successAction.name));
            return Observable.from([successAction, newAction]);
            )
            .catch(error => of(new servicesActions.LoadFailureAction(error)));
            );






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 29 '17 at 14:50

























            answered Nov 29 '17 at 13:46









            André WerlangAndré Werlang

            4,37421 silver badges42 bronze badges




            4,37421 silver badges42 bronze badges












            • I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

              – Matthis.h
              Nov 29 '17 at 13:56











            • Yes, I updated the answer

              – André Werlang
              Nov 29 '17 at 14:09











            • Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

              – Matthis.h
              Nov 29 '17 at 14:20











            • action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

              – André Werlang
              Nov 29 '17 at 14:26











            • it may be at action.name instead, given you're using classes.

              – André Werlang
              Nov 29 '17 at 14:27


















            • I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

              – Matthis.h
              Nov 29 '17 at 13:56











            • Yes, I updated the answer

              – André Werlang
              Nov 29 '17 at 14:09











            • Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

              – Matthis.h
              Nov 29 '17 at 14:20











            • action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

              – André Werlang
              Nov 29 '17 at 14:26











            • it may be at action.name instead, given you're using classes.

              – André Werlang
              Nov 29 '17 at 14:27

















            I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

            – Matthis.h
            Nov 29 '17 at 13:56





            I tried but what should I do in the effect? Do a .do (this.store.dispatch (new servicesActions.LoadConfig (action.id, action.name)))?

            – Matthis.h
            Nov 29 '17 at 13:56













            Yes, I updated the answer

            – André Werlang
            Nov 29 '17 at 14:09





            Yes, I updated the answer

            – André Werlang
            Nov 29 '17 at 14:09













            Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

            – Matthis.h
            Nov 29 '17 at 14:20





            Thx u ! Last question i need "name" which is a return value of the "LoadFullService" action, can I get it back?

            – Matthis.h
            Nov 29 '17 at 14:20













            action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

            – André Werlang
            Nov 29 '17 at 14:26





            action.payload.name is from LoadFullService. Or do you mean LoadFullServiceSuccess?

            – André Werlang
            Nov 29 '17 at 14:26













            it may be at action.name instead, given you're using classes.

            – André Werlang
            Nov 29 '17 at 14:27






            it may be at action.name instead, given you're using classes.

            – André Werlang
            Nov 29 '17 at 14:27












            0














            Effects aren't functions that take one element. They are stream transformations, and you can use all the power of RxJS here. For example, to get what you asked for in the title:



            @Effect()
            loadConfig$: Observable<Action> = this.actions$
            .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
            .switchMap(action => Observable.of(
            new OtherAction(),
            new OtherAction2(),
            );


            Note: this is quite similar to 3rd version in the André's answer.






            share|improve this answer



























              0














              Effects aren't functions that take one element. They are stream transformations, and you can use all the power of RxJS here. For example, to get what you asked for in the title:



              @Effect()
              loadConfig$: Observable<Action> = this.actions$
              .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
              .switchMap(action => Observable.of(
              new OtherAction(),
              new OtherAction2(),
              );


              Note: this is quite similar to 3rd version in the André's answer.






              share|improve this answer

























                0












                0








                0







                Effects aren't functions that take one element. They are stream transformations, and you can use all the power of RxJS here. For example, to get what you asked for in the title:



                @Effect()
                loadConfig$: Observable<Action> = this.actions$
                .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
                .switchMap(action => Observable.of(
                new OtherAction(),
                new OtherAction2(),
                );


                Note: this is quite similar to 3rd version in the André's answer.






                share|improve this answer













                Effects aren't functions that take one element. They are stream transformations, and you can use all the power of RxJS here. For example, to get what you asked for in the title:



                @Effect()
                loadConfig$: Observable<Action> = this.actions$
                .ofType<servicesActions.LoadConfig>(servicesActions.LOAD_CONFIG)
                .switchMap(action => Observable.of(
                new OtherAction(),
                new OtherAction2(),
                );


                Note: this is quite similar to 3rd version in the André's answer.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 15:45









                mik01ajmik01aj

                6,2046 gold badges52 silver badges101 bronze badges




                6,2046 gold badges52 silver badges101 bronze badges



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47554267%2fdispatch-multiple-action-from-one-effect%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript