-
Notifications
You must be signed in to change notification settings - Fork 26.5k
docs: add new signals tutorial #62750
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
Deployed adev-preview for 5765670 to: https://ng-dev-previews-fw--pr-angular-angular-62750-adev-prev-9coiyqjg.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
...utorials/signals/steps/8-using-signals-with-directives/answer/src/app/highlight-directive.ts
Outdated
Show resolved
Hide resolved
...ials/signals/steps/9-query-child-elements-with-signal-queries/answer/src/app/cart-summary.ts
Outdated
Show resolved
Hide resolved
...rc/content/tutorials/signals/steps/9-query-child-elements-with-signal-queries/src/app/app.ts
Show resolved
Hide resolved
|
||
// Query APIs to access child components | ||
firstProduct = viewChild(ProductCard); | ||
allProducts = viewChild.required(ProductCard, {read: ProductCard}); |
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.
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.
For context, this is a known issue #53894
...utorials/signals/steps/8-using-signals-with-directives/answer/src/app/highlight-directive.ts
Outdated
Show resolved
Hide resolved
3bcbb8f
to
cbb6000
Compare
adev/src/content/tutorials/signals/steps/5-managing-async-signals-with-resources-api/README.md
Outdated
Show resolved
Hide resolved
...ontent/tutorials/signals/steps/3-deriving-state-with-computed-signals/answer/src/app/app.css
Outdated
Show resolved
Hide resolved
cf0c40e
to
11e9423
Compare
11e9423
to
5765670
Compare
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.
got part of the way through, will spend some more time tomorrow
|
||
## How to use this tutorial | ||
|
||
This tutorial assumes you understand Angular's core concepts. If you're new to Angular, read our [essentials guide](/essentials). For coding best practices, see the [Angular style guide](https://angular.dev/style-guide). |
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 might leave out the reference to the style guide since there's not a whole lot that's related to signals specifically
|
||
<docs-step title="Configure OnPush change detection"> | ||
Update your component decorator to use `OnPush` change detection strategy. This is essential for components using signals as it optimizes performance by only checking for changes when signals update. | ||
|
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.
What do you think about only having a brief mention of OnPush
at the end of this step instead of it being the very first thing?
My thinking is that developers don't really need to know any about it right away, it's more like
"You might notice the ChangeDetectionStrategy.OnPush throughout this tutorial. All you need to know is that this is a performance optimization for Angular components that use signals. Feel free to ignore this for the rest of the signals tutorial."
|
||
<docs-workflow> | ||
|
||
<docs-step title="Import signal function and ChangeDetectionStrategy"> |
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.
Is it worth having a distinct step for importing symbols? My thinking is that this is more of an aside while going through another step, e.g.
Add a `userStatus` signal to your component class that is initialized with a value of `'offline'` and has types for the common statuses (i.e., online, offline, and away). You can import `signal` from `'@angular/core'`.
<h1>User Dashboard</h1> | ||
<div class="status-indicator" [class]="userStatus()"> | ||
<span class="status-dot"></span> | ||
Status: {{ userStatus() }} |
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 feel like just showing the signal by itself is maybe a bit too little for a whole step. What do you think about combining this step with the next? For the sake of the tutorial, the second step can probably be simpler- instead of three buttons and three methods, you can just directly call userStatus.set
in the template statement (<button (click)="userStatus.set('online')">Go online</button>
)
<div class="user-profile"> | ||
<h1>User Dashboard</h1> | ||
<div class="status-indicator offline"> | ||
<span class="status-dot"></span> |
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.
Looking at the current preview on the PR, this status dot doesn't seem to show up?
isAvailable = computed(() => this.userStatus() === 'online'); | ||
|
||
statusColor = computed(() => { | ||
switch (this.userStatus()) { |
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 feel like having two different computed
expressions that are both switch
statements is a bit more repetitive than helpful. I could see having two computed
expressions if one was more of a calculation, just to highlight the variety/flexibility of what you can do with computed
@@ -0,0 +1,77 @@ | |||
# Deriving state with linked signals | |||
|
|||
Now that you've learned [how to derive state with computed signals](/tutorials/signals/3-deriving-state-with-computed-signals), let's explore linked signals. Linked signals are a special type of signal that can be both read and written, while automatically deriving their value from other signals. Unlike computed signals which are read-only, linked signals can be updated directly while maintaining their reactive connection to source signals. |
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.
What do you think of starting off by showing a linkedSignal
and computed
with the same expression, and then showing that linkedSignal
is different because it can be directly updated?
@@ -0,0 +1,106 @@ | |||
# Managing async signals with Resources API |
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 think we probably wouldn't want to use the term "async signals", since we want to be clear that signals are always synchronous. It's more that resource
gives you a pattern for dealing with async data with signal APIs (i.e., the data is async, but the signals are always sync)
<docs-workflow> | ||
|
||
<docs-step title="Import resource function and API"> | ||
Add `resource` to your existing imports and import the mock API 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.
nit: I would say "fake" instead of "mock"
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
There is no dedicated signals tutorial.
What is the new behavior?
There is now a dedicated signals tutorial! 🎉
Does this PR introduce a breaking change?
Other information