-
-
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 OnInitEffects interface to dispatch an action on initialization #1467
Conversation
During a prod build the contructor name of an effect gets magnled, therefore this implementation can't be used.
* ``` | ||
*/ | ||
export interface OnIdentifyEffects { | ||
/** | ||
* @description | ||
* String identifier to differentiate effect instances. | ||
*/ | ||
ngrxOnIdentifyEffects: () => string; | ||
ngrxOnIdentifyEffects(): string; |
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.
Changed this signature to a "normal" function instead of an arrow function.
If we would use an arrow function, the function isn't being picked up at
if ( |
7916c86
to
705e29b
Compare
Fyi, it seems like the failing test command is "because" of yarn - yarnpkg/yarn#6746 and will be fixed in the next release. |
@timdeschryver instead of introducing a new hook, how about adding a configuration when registering effects to give the set a |
I think the downsides of using that approach are:
The better part would be, that it would be consistent with the config from |
Yea, I thought about manually adding effects but I think that's an advanced use case. I'd rather provide the name and use a consistent Update action then have to come up with a different one for each effect. |
Scratch that last comment. I wasn't thinking about how the effects are registered with more than one class. I'm good with the init function. |
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?
As mentioned in the issue, the solution we have now to dispatch an
INIT
effect action doesn't work in prod builds because the constructor name is mangled.Closes #1447
What is the new behavior?
This PR adds a new lifecycle hook
OnInitEffects
that dispatches a user-defined action on effect registration. I couldn't find another way to access the effect's name.Personally, I also find this solution to be cleaner and more flexible than the previous one.
Right now I've made it so that only one action can be dispatched, but this can also be an array of actions if it's needed. Imho one action is sufficient and also follows our best practices to treat an action as a unique event.
Does this PR introduce a breaking change?
Other information
The first commit reverts #1305
The second commit adds the
OnInitEffects
hook. In this commit, I also changed theOnIdentifyEffects
signature to be consistent with the other signatures.