ngRx inherited Effects classes not working

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



ngRx inherited Effects classes not working



I have two applications in a mono-repo, one will be a free subset of the other, so all of the functionality in the free one is included in the not-free one.



I'm trying to set up my Effects so that there is a core effect class that implements all of the common effects and then extend that in the not-free project to add additional effects. This isn't working. Both apps can use the core effects as long as that's all the effects I define, but as soon as I add more effects to the class for the not-free, it stops recognizing the core effects.



Here's the set up:


EffectsModule.forRoot([NotFreeEffects])


EffectsModule.forRoot([FreeEffects])



As an example, the LoadLayout effect looks like this (the others are similar):


@Effect()
loadLayout$: Observable<Action> = this.actions$
.ofType(CoreLayoutActions.LOAD_LAYOUT)
.switchMap(() => this.layoutService.loadLayout())
.map(
(layoutState: ICoreLayoutState) =>
new CoreLayoutActions.LoadLayoutSuccessAction(layoutState)
);



When I run either app with this set up, everything works. I added log statements in my reducers so I could see when the LoadLayoutSuccess message is passed and handled in the reducer.



As soon as I add another effect to the NotFreeEffect class (i.e. one not used by the free app), the core Effects are no longer handled - my log statements in the reducers no longer indicate that LoadLayoutSuccess is ever dispatched. Nothing has changed except adding a totally unrelated Effect to the not-free class. The free app continues to work, the not-free does not. If I remove that additional Effect from not-free, it begins recognizing the Core Effects again.



What am I missing? Should you be able to inherit effect classes like this?



Details:



Angular: 5.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router



@angular/cdk: 5.2.5



Thanks,



TTE




1 Answer
1



This is a known issue with various symptons. Essentially, using extends in the context of effects is buggy. My experience is that the effects in the baseclass work as long as you don't have any effects in the subclass.
https://github.com/ngrx/platform/issues/586
https://github.com/ngrx/platform/issues/1234



UPDATE: Since this commit https://github.com/ngrx/platform/commit/e7ae8a228ee4338b6beac4baf0bba745fa32c917#diff-708a6e5fc1424e81075508aee61cb59f effects no longer work at all when subclassed. Reason "hasOwnProperty"-usage instead of direct access of the effects-metadata-property.



Unfortunately the Ngrx team does not want to change this behavior
https://github.com/ngrx/platform/pull/890





OK, not the answer I was hoping for, but I won't shoot the messenger. Thanks for letting me know I'm not crazy.
– TimTheEnchanter
Aug 8 at 13:19






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS