Skip to content

Commit ad38f8a

Browse files
committed
fixup! refactor(forms): extract common parser logic
1 parent 338645a commit ad38f8a

4 files changed

Lines changed: 24 additions & 21 deletions

File tree

‎goldens/public-api/forms/signals/index.api.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ export type NgValidationError = RequiredValidationError | MinValidationError | M
431431
// @public
432432
export type OneOrMany<T> = T | readonly T[];
433433

434+
// @public
435+
export interface ParseResult<TValue> {
436+
readonly errors?: readonly ValidationError.WithoutFieldTree[];
437+
readonly value?: TValue;
438+
}
439+
434440
// @public
435441
export type PathKind = PathKind.Root | PathKind.Child | PathKind.Item;
436442

‎packages/forms/signals/src/api/transformed_value.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ import {
1414
type WritableSignal,
1515
} from '@angular/core';
1616
import {FORM_FIELD_PARSE_ERRORS} from '../directive/parse_errors';
17-
import {createParser, type ParseResult} from '../util/parser';
17+
import {createParser} from '../util/parser';
1818
import type {ValidationError} from './rules';
1919

20+
/**
21+
* Result of parsing a raw value into a model value.
22+
*/
23+
export interface ParseResult<TValue> {
24+
/**
25+
* The parsed value, if parsing was successful.
26+
*/
27+
readonly value?: TValue;
28+
/**
29+
* Errors encountered during parsing, if any.
30+
*/
31+
readonly errors?: readonly ValidationError.WithoutFieldTree[];
32+
}
33+
2034
/**
2135
* Options for `transformedValue`.
2236
*

‎packages/forms/signals/src/directive/native.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {type Renderer2, untracked} from '@angular/core';
1010
import {NativeInputParseError, WithoutFieldTree} from '../api/rules';
11+
import type {ParseResult} from '../api/transformed_value';
1112

1213
/**
1314
* Supported native control element types.
@@ -49,11 +50,6 @@ export function isTextualFormElement(element: HTMLElement): boolean {
4950
return element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';
5051
}
5152

52-
export interface NativeControlValue {
53-
value?: unknown;
54-
errors?: readonly WithoutFieldTree<NativeInputParseError>[];
55-
}
56-
5753
/**
5854
* Returns the value from a native control element.
5955
*
@@ -69,7 +65,7 @@ export interface NativeControlValue {
6965
export function getNativeControlValue(
7066
element: NativeFormControl,
7167
currentValue: () => unknown,
72-
): NativeControlValue {
68+
): ParseResult<unknown> {
7369
let modelValue: unknown;
7470

7571
if (element.validity.badInput) {

‎packages/forms/signals/src/util/parser.ts‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@
88

99
import {type Signal, linkedSignal} from '@angular/core';
1010
import type {ValidationError} from '../api/rules';
11-
12-
/**
13-
* Result of parsing a raw value into a model value.
14-
*/
15-
export interface ParseResult<TValue> {
16-
/**
17-
* The parsed value, if parsing was successful.
18-
*/
19-
value?: TValue;
20-
/**
21-
* Errors encountered during parsing, if any.
22-
*/
23-
errors?: readonly ValidationError.WithoutFieldTree[];
24-
}
11+
import type {ParseResult} from '../api/transformed_value';
2512

2613
/**
2714
* An object that handles parsing raw UI values into model values.

0 commit comments

Comments
 (0)