The RFC for Signals was published and it brought a big surprise in the form of a new component type. This episode provides a summary.
The Angular team released the RFC for Signals. Signals will be a huge shift.
It is a reactive structure that holds data, we can modify, run some side effects or create other derived signals.
Angular templates listen to Signals and update the DOM when a Signal's value changes. Today, zone.js is doing that job. It notifies Angular after a DOM event, and then it needs to go through all the components and search for a potential change. So Signals will be way more precise and efficient.
A pure Signals-based codebase will look quite different. Almost like the switch from AngularJs to Angular but with the backwards-compatibility.
And that's not just we will function calls in templates, or we have to use the new Signal's methods to update properties in the TypeScript part. The main change will be a new type of component.
Signal-based Component
A "Signal-based component" will replace the Input and Output decorator with a function. The output will still be an EventEmitter, but the input value will be read-only. So it works in the same as props do in React for example.
The lifecycle hooks will not be available. Exceptions will be NgOnInit and NgOnDestroy, although it is very unlikely that we need them. In addition, we will get new lifecycle hooks that work on an application-level. We will register them via function calls and not by implementing methods of an interface.
As it is already with standalone components, we will be able to use both Signal-based components and the old ones (zone.js component) within an application. We can even use Signal element/primiitve the in the zone.js-based components. The new features though, that I've just mentioned, will be exclusively available in the Signal-based components.
The next Steps
The Signal primitive will be available as a developer preview in Angular 16. For the new Signal-based component, we have to wait.
Further reading
Here is a list of all the relevant resources:
- Main RFC: https://github.com/angular/angular/discussions/49685
- Theory and Reasoning about Signals: https://github.com/angular/angular/discussions/49684
- API and how to use Signals: https://github.com/angular/angular/discussions/49683
- Signal-based Component: https://github.com/angular/angular/discussions/49682
- Interoperability with RxJs: https://github.com/angular/angular/discussions/49681
Last but not least the video of the Angular team discussing the RFC in detail:
Top comments (0)