Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Parent effects are setting providers for children #3

Closed
stupidawesome opened this issue Feb 25, 2020 · 2 comments
Closed

Parent effects are setting providers for children #3

stupidawesome opened this issue Feb 25, 2020 · 2 comments

Comments

@stupidawesome
Copy link
Owner

The way effects are provided it's currently not possible to scope them to the host due to a bug in the NodeInjector, which is not respecting injector flags that are passed to it.

Issue tracked here

@stupidawesome
Copy link
Owner Author

stupidawesome commented Feb 26, 2020

To workaround this issue, I am checking if the service exists in a parent injector and comparing its value to the one injected in the current injector when effects are run. In some cases this might throw an error if there are dangling providers that were provided in the parent injector but not used.

@Injectable()
export class MyEffects() {
    constructor(elementRef: ElementRef) {}

    @Effect() someEffect() {}
}

@NgModule({
    providers: [MyEffects] // dangling provider
})
export class AppModule

@Component({
    providers: [Effects, MyEffects]
})
export class AppComponent {}

MyEffects injects tokens that are not available to AppModule. We check the parent by injecting it, so it throws an error which we can't recover from. To fix this error, remove the dangling provider.

@stupidawesome
Copy link
Owner Author

Decorator API has been deprecated, composition API does not suffer from this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant