-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(effects): add user provided effects to EffectsModule.forFeature #2231
feat(effects): add user provided effects to EffectsModule.forFeature #2231
Conversation
Preview docs changes for dca891c at https://previews.ngrx.io/pr2231-dca891c/ |
This also fixes #1432 (Although it's closed, i don't know if he found a solution) |
Now that i think about it, it would be even better if you can pass instances of effects as well. So the token would be of type |
82a3a57
to
ebf724f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which use cases this feature has, in the issue it mentions that it reduces boilerplate but I'm not seeing how this can reduce it.
But it got me thinking about a different API, instead of providing the token in the forFeature
function, what about having a similar API to USER_PROVIDED_META_REDUCERS
? This would look as follows:
providers: [
{
provide: USER_PROVIDED_EFFECTS,
useValue: [FooEffect, BarEffect]
}
]
The above only if it makes sense to have a similar feature...
If we implement this we should also add the feature to use a token in the EffectsModule.forRoot()
function for consistency.
@timdeschryver Because you said you don't know how this can reduce boilerplate. Essentially you would be able to create effects, reducers and etc. at runtime, which allows you to do that in any way, shape or form. In my example i would use a base class |
Something like this: https://stackblitz.com/edit/angular-rm3eiu |
What's the status on this? |
I couldn't work on this over the holidays, i would continue today with the changes suggested |
acf934a
to
cbccef2
Compare
@brandonroberts & @timdeschryver I've made changes to this and implemented it as suggested by @timdeschryver. Also, i don't know how to fix the conflict, as every time i fix it, the githooks break it again :D |
@PsychoPflanze are you rebased on latest master? |
@brandonroberts I am yes, but the githooks correct the formatting of a specific import, which causes a conflict |
@PsychoPflanze can you try to rebase again? -export { EffectsFeatureModule } from './effects_feature_module';
+export {
+ ROOT_EFFECTS_INIT,
+ rootEffectsInit,
+ EffectsRootModule,
+} from './effects_root_module'; |
f79529a
to
ac9231e
Compare
@timdeschryver & @alex-okrushko Any updates? |
ac9231e
to
b6ea465
Compare
I've figured out how to use forks, and the pull request is now up to date with master |
I will have a look at the PR later this week. |
…to feat/effects-injection-token
Alright, i've fixed the tests and merged the tokens to |
There is a test failing i haven't touched, what should i do about it? |
I think the test fails because of the changes made in the PR. |
The test fails because in the module, multiple {
provide: _FEATURE_EFFECTS,
useValue: featureEffects,
multi: true,
}, |
Alright, thank you, i didn't notice 😄 |
I just remembered i will have to adjust the documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - just one more comment.
When you've updated the docs, feel free to ping me and we then it's ready to be merged for me :)
Nvm, the docs are already updated 🎉
Co-Authored-By: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Co-Authored-By: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks @leon-marzahn! |
When there will be a chance to make a release? or may you point me out how to build the package myself from master branch |
Builds from the master branch are here https://ngrx.io/guide/nightlies#effects |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
It is currently not possible to register effects with an
InjectionToken
like it's possible inStoreModule.forFeature
Closes #2232
What is the new behavior?
It's now possible to pass an
InjectionToken
to eitherUSER_PROVIDED_EFFECTS
to register Effects. E.g.This is useful to create consistency with
StoreModule.forFeature
and helps in making it possible to reducer boilerplate for NGRX. You could load effects by providers, which creates possibilities, e.g. putting actions, reducers and effects into a class, that is loaded via dependency injection.Does this PR introduce a breaking change?
Other information
This is my first attempt at contributing to any project, so please be easy on me :D
I couldn't write documentation yet, as i don't really know if this needs any documentation. I would appreciate some feedback and am willing for change in this.