-
-
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 OnIdentifyEffects interface to register multiple effect instances #1448
Conversation
What do you think about making the identifier something that is pulled from the effect? Like a lifecycle method that is called from the effect instance in the groupBy if present? I'd like something more defined for the identifier. |
I think that should also work, something like this right? export class FooEffects implements EffectIdentifier {
identifier = 'Foo';
} |
Yep |
684117e
to
4c96ffc
Compare
4c96ffc
to
099f5e3
Compare
I think different effect classes should be able to get instantiated even if they have the same identifier. |
I also think that getting the identifier from the class instance is not a good idea. People now have to know that "identifier" is a reserved property that the effects library uses. If someone does not implement the interface but still uses a variable called identifier for something else, strange things could happen. |
@dummdidumm I agree with:
I think |
@dummdidumm Why should it be |
SourceWithIdentifier is instantiated with identifier, "a" two times, SourceWithIdentifier 2 is instantiated with identifier "b" two times . It should be "a","b" for each effect class. Then all four should get instantiated. |
You're right, it behaves that way but the test didn't match the description. |
@@ -0,0 +1,6 @@ | |||
export interface EffectIdentifier { |
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.
Need some more doc here for the API page 😉
/**
* @description
* Interface to set an identifier for effect instances.
*
* By default, each Effects class will only be registered
* once regardless of how many times the Effect class
* is loaded. By implementing this interface, you define
* a unique identifier to register an Effects class instance
* multiple times.
*
* @usageNotes
*
* ### Set an identifier for an Effects class
*
* ```
* Example code here
* ```
*/
export interface EffectIdentifier {
/**
* @description
* String identifier to differentiate effect instances.
*/
effectIdentifier: string;
}
I still think that setting the identifier on the class is not the best possible solution.
What are your arguments against going with the initial proposal ? |
I don't have a favorite way of solving this (the first proposal vs the interface). You're right with your second point @dummdidumm , but I'm not quite agreeing with your first point. Angular does more or less do the same with their lifecycle hooks, plus it opens up opportunities to introduce more of these in NgRx e.g. in #1447. |
You are right, it opens up more possibilities, and yeah, angular does kind of the same, so I'm fine with it I guess. Regarding the API: Maybe we should decide on a prefix (like angular did with their lifecycle hooks with "ng"). "ngrx" would seem like a natural fit. |
I forgot about To stay consistent I would want to rename the property |
@timdeschryver that's fine with me because it doesn't change the public API. I'd rather see this implemented as a method if we're being similar to |
👍 I'll implement it the way you suggested. |
What about |
😂 That's fine. You're identifying this set of effects 👍 |
1f1170b
to
c0feb45
Compare
@@ -47,3 +55,34 @@ export class EffectSources extends Subject<any> { | |||
); | |||
} | |||
} | |||
|
|||
function effectsInstance(source: any) { |
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.
function effectsInstance(source: any) { | |
function effectsInstance(sourceInstance: any) { |
* @description | ||
* Interface to set an identifier for effect instances. | ||
* | ||
* By default, each Effects class will only be registered |
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.
* By default, each Effects class will only be registered | |
* By default, each Effects class is registered |
@@ -84,6 +84,12 @@ export class MyEffects { | |||
} | |||
``` | |||
|
|||
### reserved property `ngrxOnIdentifyEffects` |
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 don't think this needs to be in the migration doc as it doesn't break existing behavior. We should update the PR to a feat that adds the ngrxOnIdentifyEffects interface.
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.
The reason why I added it to the migration is that if someone would already use this property. But the chance that this is the case is probably zero.
modules/effects/src/index.ts
Outdated
export { EffectNotification } from './effect_notification'; | ||
export { ROOT_EFFECTS_INIT } from './effects_root_module'; | ||
export { UPDATE_EFFECTS, UpdateEffects } from './effects_feature_module'; | ||
export { | ||
OnIdentifyEffects, |
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.
It should be sufficient to only export the interfaces publicly
c0feb45
to
3a6d41f
Compare
@timdeschryver one more minor nit. Will you fix the first commit message with |
3a6d41f
to
8980112
Compare
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?
Closes #1443
What is the new behavior?
This change reverts #1249 in order to only instantiate effects once (e.g. when imported in different features).
This PR adds a way to identify effects while using the
addEffects
method in order to resolve #1246.Does this PR introduce a breaking change?
Other information