From b65e4e2c8739c29d833fdf070e8b9a632940cc8b Mon Sep 17 00:00:00 2001 From: ersimont <8042088+ersimont@users.noreply.github.com> Date: Sun, 5 Jun 2022 22:00:48 -0400 Subject: [PATCH] feat(ng-core): Rename `WrappedControlSuperclass.outerToInner` and similar to `.outerToInnerValues` and similar, to avoid confusion with `.outerToInnerErrors` BREAKING CHANGE: Subclasses that override one of these methods must make the same name change. --- .../lib/wrapped-control-superclass.spec.ts | 26 +++++++------- .../src/lib/wrapped-control-superclass.ts | 34 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/projects/ng-core/src/lib/wrapped-control-superclass.spec.ts b/projects/ng-core/src/lib/wrapped-control-superclass.spec.ts index f0cd46e1..2ab2a79a 100644 --- a/projects/ng-core/src/lib/wrapped-control-superclass.spec.ts +++ b/projects/ng-core/src/lib/wrapped-control-superclass.spec.ts @@ -78,7 +78,7 @@ describe('WrappedControlSuperclass', () => { lastName: new FormControl(), }); - protected override outerToInner(outer: FullName | null): FullName { + protected override outerToInnerValue(outer: FullName | null): FullName { // `outer` can come in as `null` during initialization when the user binds with `ngModel` return outer ?? new FullName(); } @@ -124,13 +124,13 @@ describe('WrappedControlSuperclass', () => { > { control = new FormControl(); - protected override setUpOuterToInner$( + protected override setUpOuterToInnerValue$( value$: Observable, ): Observable { return value$.pipe(map((outer) => String(outer / 2))); } - protected override setUpInnerToOuter$( + protected override setUpInnerToOuterValue$( value$: Observable, ): Observable { return value$.pipe( @@ -172,7 +172,7 @@ describe('WrappedControlSuperclass', () => { }); }); - it('gracefully handles an error in .innerToOuter()', () => { + it('gracefully handles an error in .innerToOuterValue()', () => { @Component({ selector: `sl-error-in`, template: ``, @@ -180,7 +180,7 @@ describe('WrappedControlSuperclass', () => { }) class ErrorInComponent extends WrappedControlSuperclass { control = new FormControl(); - override outerToInner = jasmine.createSpy(); + override outerToInnerValue = jasmine.createSpy(); } @Component({ @@ -205,18 +205,18 @@ describe('WrappedControlSuperclass', () => { ).nativeElement; const error = new Error(); - control.outerToInner.and.throwError(error); + control.outerToInnerValue.and.throwError(error); ctx.assignInputs({ value: 'wont show' }); expectSingleCallAndReset(handleError, error); expect(input.value).toBe(''); - control.outerToInner.and.returnValue('restored'); + control.outerToInnerValue.and.returnValue('restored'); ctx.assignInputs({ value: 'will show' }); expect(input.value).toBe('restored'); }); }); - it('gracefully handles an error in .outerToInner()', () => { + it('gracefully handles an error in .outerToInnerValue()', () => { @Component({ selector: `sl-error-out`, template: ``, @@ -224,7 +224,7 @@ describe('WrappedControlSuperclass', () => { }) class ErrorOutComponent extends WrappedControlSuperclass { control = new FormControl(); - override innerToOuter = jasmine.createSpy(); + override innerToOuterValue = jasmine.createSpy(); } @Component({ @@ -250,12 +250,12 @@ describe('WrappedControlSuperclass', () => { ).nativeElement; const error = new Error(); - control.innerToOuter.and.throwError(error); + control.innerToOuterValue.and.throwError(error); setValue(input, 'wont show'); expectSingleCallAndReset(handleError, error); expect(wrapper.value).toBe('initial value'); - control.innerToOuter.and.returnValue('restored'); + control.innerToOuterValue.and.returnValue('restored'); setValue(input, 'will show'); expect(wrapper.value).toBe('restored'); }); @@ -408,11 +408,11 @@ describe('WrappedControlSuperclass tests using an old style fixture', () => { class DateComponent extends WrappedControlSuperclass { control = new FormControl(); - protected override innerToOuter(value: string): Date { + protected override innerToOuterValue(value: string): Date { return new Date(value + 'Z'); } - protected override outerToInner(value: Date): string { + protected override outerToInnerValue(value: Date): string { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- happens during initialization if (value === null) { return ''; diff --git a/projects/ng-core/src/lib/wrapped-control-superclass.ts b/projects/ng-core/src/lib/wrapped-control-superclass.ts index f4c7bb2e..71337601 100644 --- a/projects/ng-core/src/lib/wrapped-control-superclass.ts +++ b/projects/ng-core/src/lib/wrapped-control-superclass.ts @@ -55,7 +55,7 @@ import { FormComponentSuperclass } from './form-component-superclass'; * lastName: new FormControl(), * }); * - * protected outerToInner(outer: FullName | null): FullName { + * protected outerToInnerValue(outer: FullName | null): FullName { * // `outer` can come in as `null` during initialization when the user binds with `ngModel` * return outer || new FullName(); * } @@ -69,11 +69,11 @@ import { FormComponentSuperclass } from './form-component-superclass'; * providers: [provideValueAccessor(DateComponent)], * }) * class DateComponent extends WrappedFormControlSuperclass { - * protected innerToOuter(inner: string): Date { + * protected innerToOuterValue(inner: string): Date { * return new Date(inner + "Z"); * } * - * protected outerToInner(outer: Date): string { + * protected outerToInnerValue(outer: Date): string { * if (outer === null) { * return ""; // happens during initialization * } @@ -101,7 +101,7 @@ export abstract class WrappedControlSuperclass this.#injector = injector; this.#errorHandler = injector.get(ErrorHandler); this.subscribeTo( - this.setUpOuterToInner$(this.#incomingValues$), + this.setUpOuterToInnerValue$(this.#incomingValues$), (inner) => { this.control.setValue(inner, { emitEvent: false }); }, @@ -111,7 +111,7 @@ export abstract class WrappedControlSuperclass ngOnInit(): void { this.#bindValidation(); this.subscribeTo( - this.setUpInnerToOuter$(this.control.valueChanges), + this.setUpInnerToOuterValue$(this.control.valueChanges), (outer) => { this.emitOutgoingValue(outer); }, @@ -143,7 +143,7 @@ export abstract class WrappedControlSuperclass * * In this example, incoming values are debounced before being passed through to the inner form control * ```ts - * setUpOuterToInner$(outer$: Observable): Observable { + * setUpOuterToInnerValue$(outer$: Observable): Observable { * return outer$.pipe( * debounce(300), * map((outer) => doExpensiveTransformToInnerValue(outer)), @@ -151,13 +151,13 @@ export abstract class WrappedControlSuperclass * } * ``` * - * For a simple transformation, see {@linkcode #outerToInner} instead. + * For a simple transformation, see {@linkcode #outerToInnerValue} instead. */ - protected setUpOuterToInner$( + protected setUpOuterToInnerValue$( outer$: Observable, ): Observable { return outer$.pipe( - map((outer) => this.outerToInner(outer)), + map((outer) => this.outerToInnerValue(outer)), this.#handleError(), ); } @@ -165,9 +165,9 @@ export abstract class WrappedControlSuperclass /** * Override this to modify a value coming from the outside to the format needed within this component. * - * For more complex needs, see {@linkcode #setUpOuterToInner$} instead. + * For more complex needs, see {@linkcode #setUpOuterToInnerValue$} instead. */ - protected outerToInner(outer: OuterType): InnerType { + protected outerToInnerValue(outer: OuterType): InnerType { return outer as unknown as InnerType; } @@ -176,20 +176,20 @@ export abstract class WrappedControlSuperclass * * In this example, illegal values are not emitted * ```ts - * setUpInnerToOuter$(inner$: Observable): Observable { + * setUpInnerToOuterValue$(inner$: Observable): Observable { * return inner$.pipe( * filter((inner) => isLegalValue(outer)), * ); * } * ``` * - * For a simple transformation, see {@linkcode #innerToOuter} instead. + * For a simple transformation, see {@linkcode #innerToOuterValue} instead. */ - protected setUpInnerToOuter$( + protected setUpInnerToOuterValue$( inner$: Observable, ): Observable { return inner$.pipe( - map((inner) => this.innerToOuter(inner)), + map((inner) => this.innerToOuterValue(inner)), this.#handleError(), ); } @@ -197,9 +197,9 @@ export abstract class WrappedControlSuperclass /** * Override this to modify a value coming from within this component to the format expected on the outside. * - * For more complex needs, see {@linkcode #setUpInnerToOuter$} instead. + * For more complex needs, see {@linkcode #setUpInnerToOuterValue$} instead. */ - protected innerToOuter(inner: InnerType): OuterType { + protected innerToOuterValue(inner: InnerType): OuterType { return inner as unknown as OuterType; }