Skip to content

Commit 9a911f5

Browse files
authored
Merge pull request #47 from cloudnc/feat/upgrade-to-angular-8
feat: upgrade to Angular 8
2 parents ac1224e + 513601d commit 9a911f5

File tree

7 files changed

+2178
-2788
lines changed

7 files changed

+2178
-2788
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.4.0

package.json

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,55 @@
3131
"commit": "git add . && git-cz"
3232
},
3333
"private": true,
34-
"resolutions": {
35-
"terser": "3.14.1"
36-
},
3734
"dependencies": {
38-
"@angular/animations": "7.2.3",
39-
"@angular/cdk": "7.3.3",
40-
"@angular/common": "7.2.3",
41-
"@angular/compiler": "7.2.3",
42-
"@angular/core": "7.2.3",
43-
"@angular/forms": "7.2.3",
44-
"@angular/http": "7.2.3",
45-
"@angular/material": "7.3.3",
46-
"@angular/platform-browser": "7.2.3",
47-
"@angular/platform-browser-dynamic": "7.2.3",
48-
"@angular/router": "7.2.3",
35+
"@angular/animations": "8.0.0",
36+
"@angular/cdk": "8.0.1",
37+
"@angular/common": "8.0.0",
38+
"@angular/compiler": "8.0.0",
39+
"@angular/core": "8.0.0",
40+
"@angular/forms": "8.0.0",
41+
"@angular/http": "7.2.15",
42+
"@angular/material": "8.0.1",
43+
"@angular/platform-browser": "8.0.0",
44+
"@angular/platform-browser-dynamic": "8.0.0",
45+
"@angular/router": "8.0.0",
4946
"@types/uuid": "3.4.4",
5047
"commitizen": "3.1.1",
51-
"core-js": "2.6.3",
52-
"rxjs": "6.4.0",
48+
"core-js": "3.1.3",
49+
"rxjs": "6.5.2",
5350
"uuid": "3.3.2",
54-
"zone.js": "0.8.29"
51+
"zone.js": "0.9.1"
5552
},
5653
"devDependencies": {
57-
"@angular-devkit/build-angular": "0.13.0",
58-
"@angular-devkit/build-ng-packagr": "0.13.0",
59-
"@angular/cli": "7.3.0",
60-
"@angular/compiler-cli": "7.2.3",
61-
"@angular/language-service": "7.2.3",
62-
"@bahmutov/add-typescript-to-cypress": "2.0.0",
63-
"@types/jasmine": "2.8.8",
64-
"@types/jasminewd2": "2.0.3",
65-
"@types/node": "10.12.21",
66-
"codelyzer": "4.5.0",
54+
"@angular-devkit/build-angular": "0.800.2",
55+
"@angular-devkit/build-ng-packagr": "0.800.2",
56+
"@angular/cli": "8.0.2",
57+
"@angular/compiler-cli": "8.0.0",
58+
"@angular/language-service": "8.0.0",
59+
"@bahmutov/add-typescript-to-cypress": "2.1.2",
60+
"@types/jasmine": "3.3.13",
61+
"@types/jasminewd2": "2.0.6",
62+
"@types/node": "12.0.7",
63+
"codelyzer": "5.1.0",
6764
"cypress": "3.2.0",
6865
"cz-conventional-changelog": "2.1.0",
6966
"http-server-spa": "1.3.0",
70-
"jasmine-core": "2.99.1",
67+
"jasmine-core": "3.4.0",
7168
"jasmine-spec-reporter": "4.2.1",
72-
"karma": "3.0.0",
69+
"karma": "4.1.0",
7370
"karma-chrome-launcher": "2.2.0",
74-
"karma-coverage-istanbul-reporter": "2.0.4",
75-
"karma-jasmine": "1.1.2",
76-
"karma-jasmine-html-reporter": "0.2.2",
77-
"ng-packagr": "4.7.0",
71+
"karma-coverage-istanbul-reporter": "2.0.5",
72+
"karma-jasmine": "2.0.1",
73+
"karma-jasmine-html-reporter": "1.4.2",
74+
"ng-packagr": "5.3.0",
7875
"prettier": "1.16.4",
79-
"semantic-release": "15.13.3",
80-
"ts-node": "8.0.2",
76+
"semantic-release": "15.13.12",
77+
"ts-node": "8.2.0",
8178
"tsconfig-paths-webpack-plugin": "3.2.0",
82-
"tsickle": "0.34.3",
83-
"tslib": "1.9.3",
84-
"tslint": "5.12.1",
85-
"typescript": "3.1.1"
79+
"tsickle": "0.35.0",
80+
"tslib": "1.10.0",
81+
"tslint": "5.17.0",
82+
"typescript": "3.4.5"
8683
},
8784
"repository": {
8885
"type": "git",

projects/ngx-sub-form/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.1",
44
"license": "MIT",
55
"peerDependencies": {
6-
"@angular/common": "^7.0.0",
7-
"@angular/core": "^7.0.0"
6+
"@angular/common": "^8.0.0",
7+
"@angular/core": "^8.0.0"
88
},
99
"keywords": [
1010
"Angular",

projects/ngx-sub-form/src/lib/ngx-sub-form-utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { AbstractControl, ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
1+
import {
2+
AbstractControl,
3+
ControlValueAccessor,
4+
NG_VALUE_ACCESSOR,
5+
NG_VALIDATORS,
6+
ValidationErrors,
7+
} from '@angular/forms';
28
import { InjectionToken, Type, forwardRef } from '@angular/core';
39
import { SUB_FORM_COMPONENT_TOKEN } from './ngx-sub-form-tokens';
410

@@ -10,6 +16,10 @@ export type ControlMap<T, V> = { [K in keyof T]-?: V };
1016

1117
export type FormUpdate<FormInterface> = { [FormControlInterface in keyof FormInterface]?: true };
1218

19+
export type FormErrors<FormInterface> = null | Partial<
20+
ControlMap<FormInterface, ValidationErrors | null> & { formGroup?: ValidationErrors }
21+
>;
22+
1323
export function subformComponentProviders(
1424
component: any,
1525
): {

projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,32 @@ import {
1616
FormUpdate,
1717
MissingFormControlsError,
1818
ArrayNotTransformedBeforeWriteValueError,
19+
FormErrors,
1920
} from './ngx-sub-form-utils';
2021
import { FormGroupOptions, OnFormUpdate, TypedFormGroup } from './ngx-sub-form.types';
2122

23+
type MapControlFunction<FormInterface, MapValue> = (ctrl: AbstractControl, key: keyof FormInterface) => MapValue;
24+
type FilterControlFunction<FormInterface> = (ctrl: AbstractControl, key: keyof FormInterface) => boolean;
25+
2226
export abstract class NgxSubFormComponent<ControlInterface, FormInterface = ControlInterface>
2327
implements ControlValueAccessor, Validator, OnDestroy, OnFormUpdate<FormInterface> {
2428
public get formGroupControls(): ControlMap<FormInterface, AbstractControl> {
25-
// @note form-group-undefined we need the as syntax here because we do not want to expose the fact that
26-
// the form can be undefined, it's hanlded internally to contain an Angular bug
27-
return this.mapControls() as ControlMap<FormInterface, AbstractControl>;
29+
// @note form-group-undefined we need the no-null-assertion here because we do not want to expose the fact that
30+
// the form can be undefined, it's handled internally to contain an Angular bug
31+
// tslint:disable-next-line:no-non-null-assertion
32+
return this.mapControls<AbstractControl>()!;
2833
}
2934

3035
public get formGroupValues(): Required<FormInterface> {
31-
// see @note form-group-undefined for as syntax
32-
return this.mapControls(ctrl => ctrl.value) as Required<FormInterface>;
36+
// see @note form-group-undefined for non-null assertion reason
37+
// tslint:disable-next-line:no-non-null-assertion
38+
return this.mapControls(ctrl => ctrl.value)!;
3339
}
3440

35-
public get formGroupErrors(): null | Partial<
36-
ControlMap<FormInterface, ValidationErrors | null> & { formGroup: ValidationErrors }
37-
> {
38-
const errors = this.mapControls<ValidationErrors | null, ControlMap<FormInterface, ValidationErrors | null>>(
39-
ctrl => ctrl.errors,
40-
ctrl => ctrl.invalid,
41-
);
41+
public get formGroupErrors(): FormErrors<FormInterface> {
42+
const errors: Partial<
43+
ControlMap<FormInterface, ValidationErrors | null>
44+
> | null = this.mapControls<ValidationErrors | null>(ctrl => ctrl.errors, ctrl => ctrl.invalid);
4245

4346
if (!this.formGroup.errors && (!errors || !Object.keys(errors).length)) {
4447
return null;
@@ -57,10 +60,10 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
5760
// when developing the lib it's a good idea to set the formGroup type
5861
// to current + `| undefined` to catch a bunch of possible issues
5962
// see @note form-group-undefined
60-
public formGroup: TypedFormGroup<FormInterface> = new FormGroup(
63+
public formGroup: TypedFormGroup<FormInterface> = (new FormGroup(
6164
this._getFormControls(),
6265
this.getFormGroupControlOptions() as AbstractControlOptions,
63-
) as any;
66+
) as unknown) as TypedFormGroup<FormInterface>;
6467

6568
protected onChange: Function | undefined = undefined;
6669
protected onTouched: Function | undefined = undefined;
@@ -92,10 +95,17 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
9295
return controls;
9396
}
9497

95-
private mapControls<MapValue, T extends ControlMap<FormInterface, MapValue>>(
96-
mapControl?: (ctrl: Controls<FormInterface>[keyof FormInterface], key: keyof FormInterface) => MapValue,
97-
filterControl: (ctrl: Controls<FormInterface>[keyof FormInterface]) => boolean = () => true,
98-
): T | null {
98+
private mapControls<MapValue>(
99+
mapControl: MapControlFunction<FormInterface, MapValue>,
100+
filterControl: FilterControlFunction<FormInterface>,
101+
): Partial<ControlMap<FormInterface, MapValue>> | null;
102+
private mapControls<MapValue>(
103+
mapControl?: MapControlFunction<FormInterface, MapValue>,
104+
): ControlMap<FormInterface, MapValue> | null;
105+
private mapControls<MapValue>(
106+
mapControl?: MapControlFunction<FormInterface, MapValue>,
107+
filterControl: FilterControlFunction<FormInterface> = () => true,
108+
): Partial<ControlMap<FormInterface, MapValue>> | null {
99109
if (!this.formGroup) {
100110
return null;
101111
}
@@ -106,18 +116,18 @@ export abstract class NgxSubFormComponent<ControlInterface, FormInterface = Cont
106116
return formControls as any;
107117
}
108118

109-
const controls: Partial<T> = {};
119+
const controls: Partial<ControlMap<FormInterface, MapValue>> = {};
110120

111121
for (const key in formControls) {
112122
if (this.formGroup.controls.hasOwnProperty(key)) {
113123
const control = formControls[key];
114-
if (control && filterControl(control)) {
124+
if (control && filterControl(control, key)) {
115125
controls[key] = mapControl(control, key);
116126
}
117127
}
118128
}
119129

120-
return controls as Required<T>;
130+
return controls;
121131
}
122132

123133
public onFormUpdate(formUpdate: FormUpdate<FormInterface>): void {}

projects/ngx-sub-form/src/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
22

3-
import 'core-js/es7/reflect';
3+
import 'core-js/proposals/reflect-metadata';
44
import 'zone.js/dist/zone';
55
import 'zone.js/dist/zone-testing';
66
import { getTestBed } from '@angular/core/testing';

0 commit comments

Comments
 (0)