Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 class used before it was declared
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryEfimenko committed Jan 11, 2022
1 parent 0522afa commit 66d27a6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
45 changes: 45 additions & 0 deletions projects/ngx-errors/src/lib/error-state-matchers.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Inject, Injectable, Optional } from '@angular/core';
import {
ErrorStateMatcher,
ShowOnDirtyErrorStateMatcher,
} from '@angular/material/core';
import {
CustomErrorStateMatchers,
CUSTOM_ERROR_STATE_MATCHERS,
} from './custom-error-state-matchers';
import {
ShowOnSubmittedErrorStateMatcher,
ShowOnTouchedAndDirtyErrorStateMatcher,
ShowOnTouchedErrorStateMatcher,
} from './error-state-matchers';

@Injectable({ providedIn: 'root' })
export class ErrorStateMatchers {
private matchers: { [key: string]: ErrorStateMatcher } = {};

constructor(
showOnTouchedErrorStateMatcher: ShowOnTouchedErrorStateMatcher,
showOnDirtyErrorStateMatcher: ShowOnDirtyErrorStateMatcher,
showOnTouchedAndDirtyErrorStateMatcher: ShowOnTouchedAndDirtyErrorStateMatcher,
showOnSubmittedErrorStateMatcher: ShowOnSubmittedErrorStateMatcher,
@Optional()
@Inject(CUSTOM_ERROR_STATE_MATCHERS)
customErrorStateMatchers: CustomErrorStateMatchers
) {
this.matchers['touched'] = showOnTouchedErrorStateMatcher;
this.matchers['dirty'] = showOnDirtyErrorStateMatcher;
this.matchers['touchedAndDirty'] = showOnTouchedAndDirtyErrorStateMatcher;
this.matchers['formIsSubmitted'] = showOnSubmittedErrorStateMatcher;
if (customErrorStateMatchers) {
this.matchers = { ...this.matchers, ...customErrorStateMatchers };
}
}

get(showWhen: string): ErrorStateMatcher | undefined {
return this.matchers[showWhen];
}

validKeys(): string[] {
return Object.keys(this.matchers);
}
}
42 changes: 2 additions & 40 deletions projects/ngx-errors/src/lib/error-state-matchers.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,6 @@
import { Inject, Injectable, Optional } from '@angular/core';
import { Injectable } from '@angular/core';
import { AbstractControl, FormGroupDirective, NgForm } from '@angular/forms';
import {
ErrorStateMatcher,
ShowOnDirtyErrorStateMatcher,
} from '@angular/material/core';
import {
CustomErrorStateMatchers,
CUSTOM_ERROR_STATE_MATCHERS,
} from './custom-error-state-matchers';

@Injectable({ providedIn: 'root' })
export class ErrorStateMatchers {
private matchers: { [key: string]: ErrorStateMatcher } = {};

constructor(
showOnTouchedErrorStateMatcher: ShowOnTouchedErrorStateMatcher,
showOnDirtyErrorStateMatcher: ShowOnDirtyErrorStateMatcher,
showOnTouchedAndDirtyErrorStateMatcher: ShowOnTouchedAndDirtyErrorStateMatcher,
showOnSubmittedErrorStateMatcher: ShowOnSubmittedErrorStateMatcher,
@Optional()
@Inject(CUSTOM_ERROR_STATE_MATCHERS)
customErrorStateMatchers: CustomErrorStateMatchers
) {
this.matchers['touched'] = showOnTouchedErrorStateMatcher;
this.matchers['dirty'] = showOnDirtyErrorStateMatcher;
this.matchers['touchedAndDirty'] = showOnTouchedAndDirtyErrorStateMatcher;
this.matchers['formIsSubmitted'] = showOnSubmittedErrorStateMatcher;
if (customErrorStateMatchers) {
this.matchers = { ...this.matchers, ...customErrorStateMatchers };
}
}

get(showWhen: string): ErrorStateMatcher | undefined {
return this.matchers[showWhen];
}

validKeys(): string[] {
return Object.keys(this.matchers);
}
}
import { ErrorStateMatcher } from '@angular/material/core';

@Injectable()
export class ShowOnTouchedErrorStateMatcher {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-errors/src/lib/error.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
import { ShowOnDirtyErrorStateMatcher } from '@angular/material/core';
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator';
import {
ErrorStateMatchers,
ShowOnSubmittedErrorStateMatcher,
ShowOnTouchedAndDirtyErrorStateMatcher,
ShowOnTouchedErrorStateMatcher,
} from './error-state-matchers';
import { ErrorStateMatchers } from './error-state-matchers.service';
import { ErrorDirective } from './error.directive';
import {
ErrorsConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-errors/src/lib/error.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { AbstractControl } from '@angular/forms';
import { merge, NEVER, Observable, of, Subscription, timer } from 'rxjs';
import { auditTime, filter, first, map, switchMap, tap } from 'rxjs/operators';
import { ErrorStateMatchers } from './error-state-matchers';
import { ErrorStateMatchers } from './error-state-matchers.service';
import { ErrorsConfiguration } from './errors-configuration';
import { ErrorsDirective } from './errors.directive';
import { extractTouchedChanges } from './misc';
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-errors/src/lib/errors.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
ShowOnDirtyErrorStateMatcher,
} from '@angular/material/core';
import {
ErrorStateMatchers,
ShowOnSubmittedErrorStateMatcher,
ShowOnTouchedAndDirtyErrorStateMatcher,
ShowOnTouchedErrorStateMatcher,
} from './error-state-matchers';
import { ErrorStateMatchers } from './error-state-matchers.service';
import { ErrorDirective } from './error.directive';
import {
ErrorsConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions projects/ngx-errors/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ErrorStateMatcher as MatErrorStateMatcher } from '@angular/material/cor
*/

export * from './lib/custom-error-state-matchers';
export * from './lib/error-state-matchers';
export * from './lib/error-state-matchers.service';
export * from './lib/error.directive';
export * from './lib/errors-configuration';
export * from './lib/errors.directive';
Expand Down

0 comments on commit 66d27a6

Please sign in to comment.