8000 Answer:51 signal bug by LMFinney · Pull Request #946 · tomalaforge/angular-challenges · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Answer:51 signal bug #946

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

Closed

Conversation

LMFinney
Copy link
Contributor

Took a break from puzzling over View Transitions to knock this one out :)

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. 🔥

@github-actions github-actions bot added 51 bug signal effect: too much triggered answer answer sponsor sponsor the project to be reviewed PR requests a review labels May 21, 2024

@Injectable({ providedIn: 'root' })
export class UserService {
name = signal('Thomas');

log(message: string) {
console.log(`${this.name()}: ${message}`);
console.log(`${untracked(() => this.name())}: ${message}`);
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 sure, i'll put the untrack here. It might make sense to track name for some other use case.

I would use the untrack inside the effect since it's where we don't want to track what's inside the function. And for instance, the log can be a library you don't own

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial commit was the minimal change to fix the bug.

Based on this feedback, I pushed another commit to move the fix to the component.

@tomalaforge tomalaforge removed the to be reviewed PR requests a review label May 21, 2024
@@ -39,7 +40,8 @@ export class ActionsComponent {

constructor() {
effect(() => {
this.userService.log(this.action() ?? 'No action selected');
const name = untracked(() => this.userService.name());
console.log(`${name}: ${this.action() ?? 'No action selected'}`);
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 still not good. I think I need to change the challenge. You cannot access name and you still need to call the log function. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it a bit more and had another idea.

Third time's a charm?

@@ -39,7 +40,8 @@ export class ActionsComponent {

constructor() {
effect(() => {
this.userService.log(this.action() ?? 'No action selected');
const action = this.action();
untracked(() => this.userService.log(action ?? 'No action selected'));
Copy link
Owner

Choose a reason for hiding this comment

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

Yes that's the right solution 👍

Copy link
github-actions bot commented Jun 2, 2024

This pull request is stale because it has been open for 15 days with no activity.

8000

@github-actions github-actions bot added the stale label Jun 2, 2024
Copy link
github-actions bot commented Jun 5, 2024

This pull request was closed because it has been inactive for 5 days since being marked as stale.

@github-actions github-actions bot closed this Jun 5, 2024
@tomalaforge tomalaforge removed the stale label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
51 bug signal effect: too much triggered answer answer sponsor sponsor the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0