-
Notifications
You must be signed in to change notification settings - Fork 27k
docs(core): primary Angular Signals documentation #50053
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
Conversation
|
Deployed aio for b110e65 to: https://ng-dev-previews-fw--pr-angular-angular-50053-3lmpdflu.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
jelbourn
left a comment
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 about halfway through before running out of steam for the night, will finish tomorrow
aio/content/guide/signals.md
Outdated
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.
| A signal is a wrapper around a value, which is capable of notifying interested consumers when that value changes. There are different kinds of signals. | |
| Some signals can have their value directly updated via a mutation API. In our implementation, these are known as "writable" signals. Updates to the model are always done by changing one or more writable signals. | |
| Because reading a signal is done through a getter, signals are able to keep track of where they're being read. And because mutations are always done with the mutation API, signals know when they're mutated and inform previous readers about the change. | |
| A **signal** is a wrapper around a value that can notify interested consumers when that value changes. Signals can contain any value, from simple primitives to complex data structures. | |
| A signal's value is always read through a getter function. When you use this getter function in certain contexts, Angular automatically creates a consumer that receives updates whenever the signal's value changes. | |
| Signals may be either _writable_ or _read-only_. |
Suggestion here to simplify this section a bit. I would also pair this with changing Writable signals and Computed signals to h3 (so that the last section is a bridge to the subsequent subsection)
aio/content/guide/signals.md
Outdated
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.
| Writable signals are created via the `signal` function, and always start with an initial value: | |
| You create writable signals by calling the `signal` function with the signal's initial value. | |
suggestion for passive voice, slightly simplified sentence structure
aio/content/guide/signals.md
Outdated
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.
| Values inside writable signals can be simple primitives or complex nested objects. In the latter case, sometimes we want to mutate those objects without needing to produce entirely new values, such as pushing new data to an array. To do that, we can use the `.mutate` operation: | |
| If your signals contains an object, you may want to mutate that object directly without creating a new instance. One common example is pushing a new value into an array. To update an object, use the `.mutate` method: |
I grabbed the first sentence here and snuck a slightly modified version of it into the introductory paragraph on signals since it seems more foundational.
We'd generally also want to avoid first-person in docs ("I" and "we"), preferring "you". Even better, though, if we can make the "you" implicit as an imperative.
JeanMeche
left a comment
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.
2 nit !
aio/content/guide/signals.md
Outdated
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.
We can keep the link relative :
| Angular signals are available for [developer preview](https://angular.io/guide/releases#developer-preview). They're ready for you to try, but may change before they are stable. | |
| Angular signals are available for [developer preview](/guide/releases#developer-preview). They're ready for you to try, but may change before they are stable. |
aio/content/guide/signals.md
Outdated
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.
Same as above 👍
| When a signal is read in the template of an `OnPush` component, that component becomes a tracked consumer of the signal. When that signal is updated and notifies its consumers, Angular will automatically mark the component for check and it will be updated the next time change detection runs. Refer to the [Skipping component subtrees](https://angular.io/guide/change-detection-skipping-subtrees) guide for more information about `OnPush` components. | |
| When a signal is read in the template of an `OnPush` component, that component becomes a tracked consumer of the signal. When that signal is updated and notifies its consumers, Angular will automatically mark the component for check and it will be updated the next time change detection runs. Refer to the [Skipping component subtrees](/guide/change-detection-skipping-subtrees) guide for more information about `OnPush` components. |
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 did a little poking around other places where we reference e.g. the developer preview guide, and they all use an absolute link.
jelbourn
left a comment
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.
Finished! Feel free to tweak these suggestions if they're not totally capture what you're trying to say; I tried to keep the concepts largely the same, just making edits for tech writing best practices.
aio/content/guide/signals.md
Outdated
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.
| Signals are useful because they can notify interested consumers when they change. An operation that's performed when the signals it depends on are changed is called an "effect". For example, Angular uses an effect to mark an `OnPush` component for check whenever any signals used within that component's template are changed. | |
| Using the `effect` function, you can create your own effects: | |
| Signals are useful because they can notify interested consumers when they change. An **effect** is an operation that runs whenever one or more signal values change. You can create an effect with the `effect` function. |
I would move the part here about OnPush to later in this section, as something like
Internally, Angular uses `effects` for its own behaviors. For example, the framework uses
an effect to mark `OnPush` components for change detection whenever any signal values
read within that component's template change.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 disagree about moving the OnPush section.
Using signals to mark OnPush components for check is the primary use case (in v16), which doesn't require understanding or creating effects.
aio/content/guide/signals.md
Outdated
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.
| Effects execute once initially, and then whenever one or more of the signals they read are updated. Like with computed signals, effects keep track of their dependencies dynamically, so signals inside conditionals that don't execute are not considered dependencies. | |
| **Effects always run at least once.** During this first run, the effect tracks any signal value reads. Whenever any of these signal values change, the effect runs again. Similar to computed signals, effects keep track of their dependencies dynamically, so the effect does not track any signal values that are not read. |
aio/content/guide/signals.md
Outdated
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 writable signals, `.mutate()` always bypasses the equality check, because it mutates the current value and doesn't produce a new one. | |
| For writable signals, `.mutate()` always ignores the equality check because it mutates the current value without producing a new reference. |
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.
Changed to "does not check for equality"
0593bbd to
928f76e
Compare
Adds the developer preview signals guide to AIO, under the preview section. This guide explains signals, computed properties, and effects.
jelbourn
left a comment
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.
LGTM
|
This PR was merged into the repository by commit 73c6126. |
Adds the developer preview signals guide to AIO, under the preview section. This guide explains signals, computed properties, and effects. PR Close #50053
Adds the developer preview signals guide to AIO, under the preview section. This guide explains signals, computed properties, and effects. PR Close angular#50053
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds the developer preview signals guide to AIO, under the preview section. This guide explains signals, computed properties, and effects.