-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
|
||
### Simplified HTTP Fetching: `httpResource()` | ||
|
||
The httpResource API (experimental) is a specialized version of resource that simplifies `HttpClient` requests. It accepts a reactive function that returns either a URL string for simple GET requests, or a full configuration object for more control. |
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.
The httpResource API (experimental) is a specialized version of resource that simplifies `HttpClient` requests. It accepts a reactive function that returns either a URL string for simple GET requests, or a full configuration object for more control. | |
The `httpResource` API (experimental) is a specialized version of resource that simplifies `HttpClient` requests. It accepts a reactive function that returns either a URL string for simple GET requests, or a full configuration object for more control. |
<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 611eeb6 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. |
|
||
## Async Patterns | ||
|
||
### Declarative Data Fetching: `resource()` |
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.
Request: could you please add an rxResource
example for the RxJS fans :0
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
<docs-code header="app/app.css" path="adev/src/content/examples/signals/src/immutability/app/app.css"/> | ||
</docs-code-multifile> | ||
|
||
## Conclusion: The Future is Reactive and Signal-Driven |
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.
IMO it's kind of odd to have a "conclusion" for a collection of code examples
@@ -0,0 +1,225 @@ | |||
# The New Age of Reactivity in Angular |
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.
IMO this title isn't really aligned with the navigation that leads here
Also, we generally want to avoid framing things as "new" in docs, since time passes and then it's stale
https://github.com/angular/angular/blob/main/contributing-docs/documentation-authoring.md
Docs should describe the framework as it exists now, never relative to a specific point in time. Docs should avoid referring to anything as "new" or "recent". Docs should avoid mentioning "upcoming" or "future" changes.
@@ -0,0 +1,225 @@ | |||
# The New Age of Reactivity in Angular | |||
|
|||
This interactive guide explores Angular Signals, a fundamental evolution in how the framework manages state and reactivity. The primary motivation behind signals is to enable fine-grained change detection, allowing Angular to know *exactly* which parts of the page have been affected by a state change and update only those specific DOM nodes. This precision is key to unlocking significant runtime performance improvements and is a critical step toward making Zone.js optional. |
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.
The primary motivation behind signals is to enable fine-grained change detection, allowing Angular to know exactly which parts of the page have been affected by a state change and update only those specific DOM nodes.
This isn't exactly wrong, but it's also misleading because Angular doesn't do fine-grained change detection (yet) today. Signals do not inherently make your app faster (zoneless does, though).
|
||
This interactive guide explores Angular Signals, a fundamental evolution in how the framework manages state and reactivity. The primary motivation behind signals is to enable fine-grained change detection, allowing Angular to know *exactly* which parts of the page have been affected by a state change and update only those specific DOM nodes. This precision is key to unlocking significant runtime performance improvements and is a critical step toward making Zone.js optional. | ||
|
||
Beyond performance, signals dramatically improve the developer experience. They offer a more explicit and predictable data flow with a simple, easy-to-understand API. This guide is your "recipe book" for learning and applying these powerful new primitives. Use the navigation on the left to explore different concepts and try the interactive examples to see signals in action. |
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.
This is perhaps a matter of opinion, but this section seems a little too hype-y
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.
Fair comment. I'll give this another crack.
|
||
### 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.
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?
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