I need some functionality to be run after any/every action, but after the reducer has run and state has changed, so meta-reducers won't work here.
Asked
Active
Viewed 538 times
1 Answers
0
I found the answer in ActionsSubject. The second answer in this question was exactly what I needed - how to subscribe to action success callback using ngrx and effects.
I needed a way to watch what was happening in ngRx because the library I'm developing needs to be able to be used in any javascript environment. It might be React or Swift, or even wrapped in a NodeJs api. I'm happy ngRx provides an easy way to monitor the actions flowing through the system - that means Angular is on the "ok list" to use our library.

Tim Hardy
- 1,654
- 1
- 17
- 36
-
Effects always fire after the reducers have been updated. The flow is: Actions -> Reducers -> Effects so if you want to fire an effect when any action is dispatched, you could just do ` effect$ = createEffect(() => this.actions.pipe(..doWhatever)) ` Since the actions arent filtered by type, they would fire on any dispatch event – the_makeshift_dev Jun 26 '21 at 01:18
-
When I tried to create an effect without an ofType filter, I received an error. That was my first thing to try. – Tim Hardy Jun 29 '21 at 15:18
-
any chance you could paste the error here? you should be able to create an effect from anything and it doesn't have to be related to the action stream. eg. you can create an effect to do something on window resize. if you haven't configure the effect to be dispatch: false, the only thing needed is that the effect should emit an action at the end – the_makeshift_dev Jun 29 '21 at 22:24
-
Sure, I probably screwed up my attempt, and I'm very open to multiple solutions. I originally posted that on gitter, but found the above solution before anyone responded. The error was "You provided 'undefined' where a stream was expected". It was a runtime error. My attempt compiled successfully. – Tim Hardy Jun 29 '21 at 23:18
-
no worries, the most important thing is to have a working solution. :) The only downside to the solution in the link imo is a philosophical one in that your component now knows about the side-effect chain. Its hard to figure out the exact issue without the code, but I've mostly encountered that error when you have a callback that doesn't return anything in the operator chain. eg. mergeMap(() => doSomething() //doSomething doesnt return anything ), catchError... – the_makeshift_dev Jun 30 '21 at 22:39