-
Notifications
You must be signed in to change notification settings - Fork 27k
refactor(devtools): Internal signals prototype #66099
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| load("//devtools/tools:defaults.bzl", "ng_project") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| ng_project( | ||
| name = "forms", | ||
| srcs = [ | ||
| "forms.component.ts", | ||
| ], | ||
| deps = [ | ||
| "//:node_modules/@angular/core", | ||
| "//:node_modules/@angular/forms", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {Component} from '@angular/core'; | ||
| import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-forms', | ||
| imports: [ReactiveFormsModule], | ||
| template: ` | ||
| <form [formGroup]="profileForm"> | ||
| <label> | ||
| First Name: | ||
| <input formControlName="firstName" /> | ||
| </label> | ||
|
|
||
| <label> | ||
| Last Name: | ||
| <input formControlName="lastName" /> | ||
| </label> | ||
|
|
||
| <button type="submit">Submit</button> | ||
| </form> | ||
| `, | ||
| }) | ||
| export class FormsComponent { | ||
| profileForm = new FormGroup({ | ||
| firstName: new FormControl(''), | ||
| lastName: new FormControl(''), | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,11 @@ export interface CreateComputedOptions<T> { | |
| * A debug name for the computed signal. Used in Angular DevTools to identify the signal. | ||
| */ | ||
| debugName?: string; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| isInternal?: boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider: Would
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -35,6 +40,7 @@ export function computed<T>(computation: () => T, options?: CreateComputedOption | |
| if (ngDevMode) { | ||
| getter.toString = () => `[Computed: ${getter()}]`; | ||
| getter[SIGNAL].debugName = options?.debugName; | ||
| (getter[SIGNAL] as any).isInternal = options?.isInternal ?? false; | ||
| } | ||
|
|
||
| return getter; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,8 +70,14 @@ export abstract class AbstractFormDirective | |
| this._submittedReactive.set(value); | ||
| } | ||
| /** @internal */ | ||
| readonly _submitted = computed(() => this._submittedReactive()); | ||
| private readonly _submittedReactive = signal(false); | ||
| readonly _submitted = computed( | ||
| () => this._submittedReactive(), | ||
| ...(ngDevMode ? [{isInternal: true} as any] : []), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider: It seems easy to forget the IIRC, the debug name transform wraps an explicit name in an // Definition
interface DebugInfo {
name?: string;
isInternal?: boolean;
}
declare function signal<T>(initial: T, opts?: {debugInfo?: DebugInfo}): WritableSignal<T>;
// Dev writes:
const foo = signal(0, {
debugInfo: {isInternal: true},
});
// Transformed to (using our existing infra, just tweaked for `debugInfo` instead of `debugName`):
const foo = signal(0, {
...(ngDevMode ? {
debugInfo: {
name: 'foo',
isInternal: true,
},
} : {})
});This way we don't need to think about tree shaking at each call site, we just annotate which signals are internal. I know we're just experimenting here for now, so I'm fine to come back to this later. I'm mainly calling out that there might be value in a |
||
| ); | ||
| private readonly _submittedReactive = signal( | ||
| false, | ||
| ...(ngDevMode ? [{isInternal: true} as any] : []), | ||
| ); | ||
|
|
||
| /** | ||
| * Reference to an old form group input value, which is needed to cleanup | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.