Skip to content

Commit

Permalink
feat: sync on touched change with parent layout #353
Browse files Browse the repository at this point in the history
  • Loading branch information
ZurabDev committed Oct 9, 2023
1 parent a80e396 commit dc39be5
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export abstract class PrizmInputNgControl<T>
readonly changeDetectorRef!: ChangeDetectorRef;
readonly layoutComponent!: PrizmInputLayoutComponent;
private previousInternalValue$$ = new BehaviorSubject<T | null>(null);
private lastState = {
touched: false,
pristine: true,
private readonly lastSyncedState: {
touched: boolean | null;
pristine: boolean | null;
} = {
touched: null,
pristine: null,
};
onChange: (val: T) => void = PRIZM_EMPTY_FUNCTION;
onTouch: (val: T) => void = PRIZM_EMPTY_FUNCTION;
Expand Down Expand Up @@ -214,12 +217,12 @@ export abstract class PrizmInputNgControl<T>
}

private updateLayoutOnTouched(): void {
if (this.ngControl.pristine !== this.lastState.pristine) {
this.lastState.pristine = !!this.ngControl.pristine;
this.stateChanges.next();
}
if (this.ngControl.touched !== this.lastState.touched) {
this.lastState.touched = !!this.ngControl.touched;
if (
this.ngControl.pristine !== this.lastSyncedState.pristine ||
this.ngControl.touched !== this.lastSyncedState.touched
) {
this.lastSyncedState.touched = this.ngControl.touched;
this.lastSyncedState.pristine = this.ngControl.pristine;
this.stateChanges.next();
}
}
Expand Down

0 comments on commit dc39be5

Please sign in to comment.