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

Commit

Permalink
fix: 🐛 provide config defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryEfimenko committed Jan 11, 2022
1 parent 82ddc95 commit 5242c70
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,16 @@ markDescendantsAsDirty(formControl);

### Basic Workflow

One time config: `git config --global push.followTags true`

1. Develop
1. Write specs
1. Run `npm run test:lib`
1. Run `npm run commit` and choose fix or feature
1. Run `npm run release`
1. Run `npm run build:lib`
1. Go to the dist directory and run `npm publish`
1. Push changes `git push`

### Scripts

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:lib:coverage": "npm run test:lib -- --code-coverage",
"postbuild:lib": "copyfiles README.md logo.png dist/ngx-errors",
"release": "cd projects/ngx-errors && standard-version --infile ../../CHANGELOG.md",
"release:dry": "cd projects/ngx-errors && standard-version --infile ../../CHANGELOG.md --dry-run",
"commitlint": "commitlint",
"prepare": "husky install"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-errors/src/lib/errors-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export interface IErrorsConfiguration {
@Injectable()
export class ErrorsConfiguration implements IErrorsConfiguration {
showErrorsWhenInput = 'touched';
showMaxErrors = undefined;
showMaxErrors: number | undefined = undefined;
}
15 changes: 13 additions & 2 deletions projects/ngx-errors/src/lib/errors.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ const declarationsAndExports = [
SetMatInputErrorStateMatcherDirective,
];

const defaultConfig: ErrorsConfiguration = {
showErrorsWhenInput: 'touched',
showMaxErrors: undefined,
};

function mergeErrorsConfiguration(
config: IErrorsConfiguration
): ErrorsConfiguration {
return { ...defaultConfig, ...config };
}

@NgModule({
imports: [ReactiveFormsModule],
declarations: [...declarationsAndExports],
Expand All @@ -37,14 +48,14 @@ const declarationsAndExports = [
})
export class NgxErrorsModule {
static configure(
config?: IErrorsConfiguration
config: IErrorsConfiguration
): ModuleWithProviders<NgxErrorsModule> {
return {
ngModule: NgxErrorsModule,
providers: [
{
provide: ErrorsConfiguration,
useValue: config,
useValue: mergeErrorsConfiguration(config),
},
{
provide: ErrorStateMatcher,
Expand Down

0 comments on commit 5242c70

Please sign in to comment.