Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b542302

Browse filesBrowse files
volkanfilazileonsenft
authored andcommitted
fix(forms/signals): make extractValue reactive for compat AbstractControl values
1 parent 3cd98ff commit b542302
Copy full SHA for b542302

2 files changed

+40-2Lines changed: 40 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/forms/signals/compat/src/api/extract.ts‎

Copy file name to clipboardExpand all lines: packages/forms/signals/compat/src/api/extract.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function extractValue<T>(
8787
field: FieldTree<T>,
8888
filter?: ExtractFilter,
8989
): RawValue<T> | DeepPartial<RawValue<T>> {
90-
return untracked(() => visitFieldTree(field, filter)) as RawValue<T> | DeepPartial<RawValue<T>>;
90+
return visitFieldTree(field, filter) as RawValue<T> | DeepPartial<RawValue<T>>;
9191
}
9292

9393
function visitFieldTree(
@@ -96,6 +96,7 @@ function visitFieldTree(
9696
): RawValue<unknown> | DeepPartial<RawValue<unknown>> {
9797
const state = field();
9898
const value = state.value();
99+
console.log('value', value);
99100

100101
const matchingChildren = extractChildren(field, value, filter);
101102

Collapse file

‎packages/forms/signals/test/node/compat/extract_value.spec.ts‎

Copy file name to clipboardExpand all lines: packages/forms/signals/test/node/compat/extract_value.spec.ts
+38-1Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Injector, signal} from '@angular/core';
9+
import {computed, effect, Injector, runInInjectionContext, signal} from '@angular/core';
1010
import {TestBed} from '@angular/core/testing';
1111
import {FormControl, FormGroup} from '@angular/forms';
1212
import {applyEach, disabled, form} from '@angular/forms/signals';
@@ -61,6 +61,43 @@ describe('extractValue', () => {
6161
});
6262
});
6363

64+
it('should notify reactive consumers when AbstractControl value changes', () => {
65+
const formGroup = new FormGroup({
66+
firstName: new FormControl('Max'),
67+
lastName: new FormControl('Maxer'),
68+
});
69+
70+
const f = compatForm(signal(formGroup), {injector});
71+
const unwrapped = computed(() => extractValue(f));
72+
73+
let runs = 0;
74+
let latest: unknown;
75+
76+
runInInjectionContext(injector, () => {
77+
effect(() => {
78+
runs++;
79+
latest = unwrapped();
80+
});
81+
});
82+
83+
TestBed.tick();
84+
85+
expect(runs).toBe(1);
86+
expect(latest).toEqual({
87+
firstName: 'Max',
88+
lastName: 'Maxer',
89+
});
90+
91+
formGroup.get('lastName')?.setValue('NotMaxer');
92+
TestBed.tick();
93+
94+
expect(runs).toBe(2);
95+
expect(latest).toEqual({
96+
firstName: 'Max',
97+
lastName: 'NotMaxer',
98+
});
99+
});
100+
64101
it('should unwrap nested FormGroup in compatForm', () => {
65102
const group = new FormGroup({
66103
inner: new FormControl('value'),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.