-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Answer:51 signal bug #946
Conversation
|
||
@Injectable({ providedIn: 'root' }) | ||
export class UserService { | ||
name = signal('Thomas'); | ||
|
||
log(message: string) { | ||
console.log(`${this.name()}: ${message}`); | ||
console.log(`${untracked(() => this.name())}: ${message}`); |
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, 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
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.
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.
@@ -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'}`); |
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 still not good. I think I need to change the challenge. You cannot access name and you still need to call the log function. 😅
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 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')); |
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.
Yes that's the right solution 👍
This pull request is stale because it has been open for 15 days with no activity. |
This pull request was closed because it has been inactive for 5 days since being marked as stale. |
Took a break from puzzling over View Transitions to knock this one out :)
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. 🔥