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

Commit 66d27a6

Browse files
fix: 🐛 class used before it was declared
1 parent 0522afa commit 66d27a6

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-43
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Inject, Injectable, Optional } from '@angular/core';
2+
import {
3+
ErrorStateMatcher,
4+
ShowOnDirtyErrorStateMatcher,
5+
} from '@angular/material/core';
6+
import {
7+
CustomErrorStateMatchers,
8+
CUSTOM_ERROR_STATE_MATCHERS,
9+
} from './custom-error-state-matchers';
10+
import {
11+
ShowOnSubmittedErrorStateMatcher,
12+
ShowOnTouchedAndDirtyErrorStateMatcher,
13+
ShowOnTouchedErrorStateMatcher,
14+
} from './error-state-matchers';
15+
16+
@Injectable({ providedIn: 'root' })
17+
export class ErrorStateMatchers {
18+
private matchers: { [key: string]: ErrorStateMatcher } = {};
19+
20+
constructor(
21+
showOnTouchedErrorStateMatcher: ShowOnTouchedErrorStateMatcher,
22+
showOnDirtyErrorStateMatcher: ShowOnDirtyErrorStateMatcher,
23+
showOnTouchedAndDirtyErrorStateMatcher: ShowOnTouchedAndDirtyErrorStateMatcher,
24+
showOnSubmittedErrorStateMatcher: ShowOnSubmittedErrorStateMatcher,
25+
@Optional()
26+
@Inject(CUSTOM_ERROR_STATE_MATCHERS)
27+
customErrorStateMatchers: CustomErrorStateMatchers
28+
) {
29+
this.matchers['touched'] = showOnTouchedErrorStateMatcher;
30+
this.matchers['dirty'] = showOnDirtyErrorStateMatcher;
31+
this.matchers['touchedAndDirty'] = showOnTouchedAndDirtyErrorStateMatcher;
32+
this.matchers['formIsSubmitted'] = showOnSubmittedErrorStateMatcher;
33+
if (customErrorStateMatchers) {
34+
this.matchers = { ...this.matchers, ...customErrorStateMatchers };
35+
}
36+
}
37+
38+
get(showWhen: string): ErrorStateMatcher | undefined {
39+
return this.matchers[showWhen];
40+
}
41+
42+
validKeys(): string[] {
43+
return Object.keys(this.matchers);
44+
}
45+
}

projects/ngx-errors/src/lib/error-state-matchers.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
1-
import { Inject, Injectable, Optional } from '@angular/core';
1+
import { Injectable } from '@angular/core';
22
import { AbstractControl, FormGroupDirective, NgForm } from '@angular/forms';
3-
import {
4-
ErrorStateMatcher,
5-
ShowOnDirtyErrorStateMatcher,
6-
} from '@angular/material/core';
7-
import {
8-
CustomErrorStateMatchers,
9-
CUSTOM_ERROR_STATE_MATCHERS,
10-
} from './custom-error-state-matchers';
11-
12-
@Injectable({ providedIn: 'root' })
13-
export class ErrorStateMatchers {
14-
private matchers: { [key: string]: ErrorStateMatcher } = {};
15-
16-
constructor(
17-
showOnTouchedErrorStateMatcher: ShowOnTouchedErrorStateMatcher,
18-
showOnDirtyErrorStateMatcher: ShowOnDirtyErrorStateMatcher,
19-
showOnTouchedAndDirtyErrorStateMatcher: ShowOnTouchedAndDirtyErrorStateMatcher,
20-
showOnSubmittedErrorStateMatcher: ShowOnSubmittedErrorStateMatcher,
21-
@Optional()
22-
@Inject(CUSTOM_ERROR_STATE_MATCHERS)
23-
customErrorStateMatchers: CustomErrorStateMatchers
24-
) {
25-
this.matchers['touched'] = showOnTouchedErrorStateMatcher;
26-
this.matchers['dirty'] = showOnDirtyErrorStateMatcher;
27-
this.matchers['touchedAndDirty'] = showOnTouchedAndDirtyErrorStateMatcher;
28-
this.matchers['formIsSubmitted'] = showOnSubmittedErrorStateMatcher;
29-
if (customErrorStateMatchers) {
30-
this.matchers = { ...this.matchers, ...customErrorStateMatchers };
31-
}
32-
}
33-
34-
get(showWhen: string): ErrorStateMatcher | undefined {
35-
return this.matchers[showWhen];
36-
}
37-
38-
validKeys(): string[] {
39-
return Object.keys(this.matchers);
40-
}
41-
}
3+
import { ErrorStateMatcher } from '@angular/material/core';
424

435
@Injectable()
446
export class ShowOnTouchedErrorStateMatcher {

projects/ngx-errors/src/lib/error.directive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
import { ShowOnDirtyErrorStateMatcher } from '@angular/material/core';
1212
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator';
1313
import {
14-
ErrorStateMatchers,
1514
ShowOnSubmittedErrorStateMatcher,
1615
ShowOnTouchedAndDirtyErrorStateMatcher,
1716
ShowOnTouchedErrorStateMatcher,
1817
} from './error-state-matchers';
18+
import { ErrorStateMatchers } from './error-state-matchers.service';
1919
import { ErrorDirective } from './error.directive';
2020
import {
2121
ErrorsConfiguration,

projects/ngx-errors/src/lib/error.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { AbstractControl } from '@angular/forms';
1111
import { merge, NEVER, Observable, of, Subscription, timer } from 'rxjs';
1212
import { auditTime, filter, first, map, switchMap, tap } from 'rxjs/operators';
13-
import { ErrorStateMatchers } from './error-state-matchers';
13+
import { ErrorStateMatchers } from './error-state-matchers.service';
1414
import { ErrorsConfiguration } from './errors-configuration';
1515
import { ErrorsDirective } from './errors.directive';
1616
import { extractTouchedChanges } from './misc';

projects/ngx-errors/src/lib/errors.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
ShowOnDirtyErrorStateMatcher,
66
} from '@angular/material/core';
77
import {
8-
ErrorStateMatchers,
98
ShowOnSubmittedErrorStateMatcher,
109
ShowOnTouchedAndDirtyErrorStateMatcher,
1110
ShowOnTouchedErrorStateMatcher,
1211
} from './error-state-matchers';
12+
import { ErrorStateMatchers } from './error-state-matchers.service';
1313
import { ErrorDirective } from './error.directive';
1414
import {
1515
ErrorsConfiguration,

projects/ngx-errors/src/public-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ErrorStateMatcher as MatErrorStateMatcher } from '@angular/material/cor
44
*/
55

66
export * from './lib/custom-error-state-matchers';
7+
export * from './lib/error-state-matchers';
8+
export * from './lib/error-state-matchers.service';
79
export * from './lib/error.directive';
810
export * from './lib/errors-configuration';
911
export * from './lib/errors.directive';

0 commit comments

Comments
 (0)