-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Answer:7 Power of effects #913
base: main
Are you sure you want to change the base?
Conversation
update to new control flow use selectSignal where possible in components
Replace notification service with injected push service
add effect for snackbar
You don't have to worry about lazy loading because you used the lifecycle methods of component store. The injection token approach makes more sense if you don't (or can't) convert all components to use Component Stores. |
teacherActions.addOneTeacher, | ||
), | ||
map((action) => { | ||
switch (action.type) { |
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 a big fan of switch statement in effect. You should create separate effects for each use cases
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'll tweak it
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 just pushed two commits:
- One to split the effect into four effects (1 for each of the three notification types, and one to do the actual alert).
- Converted to functional effects (just for practice).
{ | ||
factory: () => inject(PushService).notification$, | ||
}, | ||
); |
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.
That's the tricky part and you did it well. Nice job.
|
||
ngrxOnStateInit() { | ||
this.effect(() => | ||
inject(PUSH_TOKEN).pipe( |
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.
That's the second point I want to highly with this challenge, it's that we can use any observable inside an effect and not only the Ngrx action observbale. Effect is just a subscription.
Nice work
Very nice work and I think you are the first one to complete the challenge. I was going to suppress it 馃槄 |
Change one effect with a switch statement to four effects
Did this just for the practice
@@ -24,10 +20,12 @@ export class AppEffects { | |||
}), | |||
map((message) => appApiActions.alert({ message })), | |||
), | |||
); | |||
{ functional: true }, | |||
); |
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 if I achieved step 4 - I'm not sure what you intended.
We could have injected the PushService directly wherever the injection token was used, right?
Checklist for challenge submission
Warning:
Alternatively, you can still submit your PR to join the list of answered challenges or to be reviewed by a community member. 馃敟