Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

LMFinney
Copy link
Sponsor Contributor

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

  • Start your PR message with Answer:${challenge_number}

Warning:

  • If you want feedback or review, you must support the project on GitHub:

Alternatively, you can still submit your PR to join the list of answered challenges or to be reviewed by a community member. 馃敟

update to new control flow
use selectSignal where possible in components
Replace notification service with injected push service
add effect for snackbar
@github-actions github-actions bot added 7 exercice power of effects answer answer sponsor sponsor the project to be reviewed PR requests a review labels May 14, 2024
@jdegand
Copy link
Contributor

jdegand commented May 14, 2024

You don't have to worry about lazy loading because you used the lifecycle methods of component store.
In the initial app, all the lists are constantly growing.

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) {
Copy link
Owner

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

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll tweak it

Copy link
Sponsor Contributor Author

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:

  1. One to split the effect into four effects (1 for each of the three notification types, and one to do the actual alert).
  2. Converted to functional effects (just for practice).

{
factory: () => inject(PushService).notification$,
},
);
Copy link
Owner

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(
Copy link
Owner

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

@tomalaforge tomalaforge removed the to be reviewed PR requests a review label May 20, 2024
@tomalaforge
Copy link
Owner

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 },
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7 exercice power of effects answer answer sponsor sponsor the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants