-
Notifications
You must be signed in to change notification settings - Fork 26.4k
docs: add signals code example recipe book #62164
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
base: main
Are you sure you want to change the base?
Conversation
<div class="result-box"> | ||
<div class="display-section"> | ||
<h3>Current User:</h3> | ||
<pre>{{ '{' }} |
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.
suggestion: use JsonPipe
instead
Deployed adev-preview for 790c47a to: https://ng-dev-previews-fw--pr-angular-angular-62164-adev-prev-a8hbslfy.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
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.
Can this be updated to use semantic HTML elements? Currently, div
elements are used where there are better, more screen-reader friendly elements available such as section
|
||
### The Source of Truth: `signal()` | ||
|
||
A writable signal, created with the `signal()` function, is the foundation of all reactive state. It's a container for a value that notifies consumers when it changes. You create it with an initial value and read it by calling it as a function, like `mySignal()`. State is changed using the `.set()` or `.update()` methods. |
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 worry a little that the framing text around the examples is doing too much work that duplicates the explanatory/introductory content we would have in the other topics/tutorials. IMO we should have one canonical journey where we explain the concepts in a particular guide, and reinforce that with examples
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've replaced the description text with links to relevant guides, unless there was no relevant guide, in which case I left the text as a stopgap. Thanks for the discussion here - I think this solution works well.
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.
Hey @devchas! I like the way the code examples help to illustrate different concepts of signals.
As far as the explainers go though, I think it currently is at odds with the rest of the guide. Would it be possible to refactor this PR as enhancements to the guide as inline examples rather than a separate page?
@@ -0,0 +1,38 @@ | |||
<div class="container"> | |||
<h2>Demo: Immutability</h2> | |||
<p>Always produce a new value when updating a signal that holds an object or array. Direct mutation, like using <code>.push()</code>, will not be detected by Angular's change detection. </p> |
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.
@MarkTechson Hi Mark, is the importance of immutability currently part of the AI rules files?
My personal experience is that proposed code snippets from AI often fall short on this.
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.
Thanks for prototyping this initial concept @devchas! Let's put a pause on this for now and chat more with Jeremy to figure out the best way to enhance code examples on the docs site.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information