Skip to content

docs(core): Update linked-signal.md #58756

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
wants to merge 1 commit into from

Conversation

robertIsaac
Copy link
Contributor

@robertIsaac robertIsaac commented Nov 19, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

fix multiple issues with the existing code sample

  1. shippingOptions was accessed without this. which produces error in realtime
  2. the logic in calculating of the item exist or not was not correct since it was comparing the object to the id
  3. I'm not sure why, but step 3 fail without stating typing for LinkedSignal, so I added it

What is the new behavior?

fixes these issues

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove bot requested a review from crisbeto November 19, 2024 21:36
@@ -61,15 +61,15 @@ In the example above, `selectedOption` always updates back to the first option w
```typescript
@Component({/* ... */})
export class ShippingMethodPicker {
shippingOptions: Signal<ShippingMethod[]> = getShippingOptions();
shippingOptions: WritableSignal<ShippingMethod[]> = getShippingOptions();
Copy link
Member

Choose a reason for hiding this comment

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

shippingOptions could an input, why do you think it should be describe as a writable ? It's not being written to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

without it value is of type unknown, and so can't use .id in it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

You're probably answer to the comment I deleted, I got that. I'll investigate if we can improve that. Ideally the generics should be inferred !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah sorry 😅

Copy link
Contributor Author

@robertIsaac robertIsaac Nov 19, 2024

Choose a reason for hiding this comment

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

about Writable because it's not an input, now it's impossible to give it a new value
so either make it to equal input, or leave it WritableSignal IMO
I will revert this small change if you insist

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should make it an input, wdyt @jelbourn ?

Copy link
Member

Choose a reason for hiding this comment

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

One of my goals with this doc was is to not explicitly require people understand the component-based signal APIs first.

As to the original suggestion: there's actually nothing wrong with this being a Signal here. Any signal's value can change; just because this code in the example can't directly change it, doesn't mean the value can't change elsewhere (i.e., somewhere inside getShippingOptions there's a writable signal, but that function returns it asReadOnly)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@thePunderWoman thePunderWoman added the area: docs Related to the documentation label Nov 20, 2024
@ngbot ngbot bot added this to the Backlog milestone Nov 20, 2024
@angular-robot angular-robot bot removed the area: docs Related to the documentation label Nov 20, 2024
@ngbot ngbot bot removed this from the Backlog milestone Nov 20, 2024
@thePunderWoman thePunderWoman added the area: docs Related to the documentation label Nov 21, 2024
@ngbot ngbot bot added this to the Backlog milestone Nov 21, 2024
@thePunderWoman thePunderWoman added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Nov 21, 2024
@thePunderWoman
Copy link
Contributor

@robertIsaac Your commit message needs to be updated to fix the broken lint tests. Can you change that and force push? We can merge it after that's green.

fix multiple issues with the existing code
1. `shippingOptions` was accessed without `this.` which produces error in realtime
2. the logic in calculating of the item exist or not was not correct since it was comparing the object to the id
3. I'm not sure why, but step 3 fail without stating typing for LinkedSignal, so I added it
@robertIsaac
Copy link
Contributor Author

@thePunderWoman done

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Nov 22, 2024
@thePunderWoman thePunderWoman added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 22, 2024
@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 28, 2024
pkozlowski-opensource pushed a commit that referenced this pull request Nov 28, 2024
fix multiple issues with the existing code
1. `shippingOptions` was accessed without `this.` which produces error in realtime
2. the logic in calculating of the item exist or not was not correct since it was comparing the object to the id
3. I'm not sure why, but step 3 fail without stating typing for LinkedSignal, so I added it

PR Close #58756
@pkozlowski-opensource
Copy link
Member

This PR was merged into the repository by commit e495a68.

The changes were merged into the following branches: main, 19.0.x

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime area: docs Related to the documentation target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants