Skip to content

Commit 5eb168e

Browse files
Turn tsconfig settings to 11 (#34)
* `"strict": true,` * `"noUnusedLocals": true,` * `"noUnusedParameters": true,` * `"forceConsistentCasingInFileNames": true,` Also updated to typescript 2.4.1. Also simplify the implementation of composeReducers. The composed reducer will assemble initial state automatically during Redux initialization; we don't need to do all that state manipulation manually. Fixes #26
1 parent 9be95ba commit 5eb168e

13 files changed

+61
-74
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ dist
4848

4949
source/*ngfactory.ts
5050
source/*ngsummary.json
51+
52+
*.tgz

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage/
88
.vscode/
99
docs/
1010
webpack/
11+
*.tgz

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-redux/form",
3-
"version": "6.5.1",
3+
"version": "6.5.2",
44
"description": "Build Angular 2+ forms with Redux",
55
"dependencies": {
66
"immutable": "^3.8.1"
@@ -42,7 +42,7 @@
4242
"reflect-metadata": "^0.1.3",
4343
"rimraf": "^2.5.4",
4444
"rxjs": "^5.0.1",
45-
"typescript": "^2.1.0",
45+
"typescript": "^2.4.1",
4646
"webpack": "^2.1.0-beta.25",
4747
"zone.js": "^0.8.4"
4848
},

source/compose-reducers.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
import {Reducer, Action} from 'redux';
22

3-
import {State} from './state';
4-
53
export const composeReducers =
6-
<State>(...reducers: Reducer<State>[]): Reducer<State> => {
7-
// Pull from each reducer its initial state value, from the default
8-
// value of the `state' argument. So we are provided with {initialState},
9-
// and then with the individual initial states of each reducer. We
10-
// compose all these states together to produce a true 'initial state'
11-
// for our composed reducer.
12-
let state: State = null;
13-
14-
for (const reducer of reducers) {
15-
const result = reducer.apply(null, [undefined, {type: ''}]);
16-
if (result === undefined) {
17-
continue;
18-
}
19-
20-
if (state == null) {
21-
state = result;
22-
}
23-
else {
24-
state = State.inspect(state).merge(null, result);
25-
}
26-
}
27-
28-
return (s: State = state, action: Action) =>
29-
reducers.reduce((st, reducer) => reducer(st, action), s);
30-
};
4+
<State>(...reducers: Reducer<State>[]): Reducer<State> =>
5+
(s: State, action: Action) =>
6+
reducers.reduce((st, reducer) => reducer(st, action), s);

source/connect-array.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import {controlPath, selectValueAccessor} from './shims';
4343

4444
export class ConnectArrayTemplate {
4545
constructor(
46-
public $implicit,
46+
public $implicit: any,
4747
public index: number,
48-
public item
48+
public item: any
4949
) {}
5050
}
5151

@@ -85,7 +85,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
8585
}
8686

8787
@Input()
88-
set connectArrayOf(collection) {
88+
set connectArrayOf(collection: any) {
8989
this.key = collection;
9090

9191
this.resetState(this.store.getState());
@@ -131,7 +131,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
131131
this.formDirective.form.removeControl(this.key);
132132
}
133133

134-
private resetState(state) {
134+
private resetState(state: any) {
135135
if (this.key == null || this.key.length === 0) {
136136
return; // no state to retreive if no key is set
137137
}
@@ -174,7 +174,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
174174
}
175175
}
176176

177-
private registerInternals(array) {
177+
private registerInternals(array: any) {
178178
array.registerControl = () => {};
179179
array.registerOnChange = () => {};
180180

@@ -188,7 +188,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
188188
});
189189
}
190190

191-
private patchDescendantControls(viewRef) {
191+
private patchDescendantControls(viewRef: any) {
192192
const groups = Object.keys(viewRef._view)
193193
.map(k => viewRef._view[k])
194194
.filter(c => c instanceof NgModelGroup);
@@ -205,7 +205,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
205205
});
206206
}
207207

208-
private transform(parent: FormGroup | FormArray, reference): AbstractControl {
208+
private transform(parent: FormGroup | FormArray, reference: any): AbstractControl {
209209
const emptyControl = () => {
210210
const control = new FormControl(null);
211211
control.setParent(parent);
@@ -227,7 +227,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
227227
return emptyControl();
228228
}
229229

230-
const iterate = (iterable): FormArray => {
230+
const iterate = (iterable: any): FormArray => {
231231
const array = new FormArray([]);
232232

233233
this.registerInternals(array);
@@ -246,7 +246,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
246246
return array;
247247
}
248248

249-
const associate = (value): FormGroup => {
249+
const associate = (value: any): FormGroup => {
250250
const group = new FormGroup({});
251251
group.setParent(parent);
252252

@@ -280,7 +280,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
280280

281281
private simpleAccessor() {
282282
return {
283-
writeValue: value => this.control.setValue(value),
283+
writeValue: (value: any) => this.control.setValue(value),
284284
registerOnChange() {},
285285
registerOnTouched() {}
286286
};

source/connect-base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ConnectBase {
2929

3030
private formSubscription: Subscription;
3131
protected store: FormStore;
32-
protected form;
32+
protected form: any;
3333

3434
public get path(): Array<string> {
3535
const path = typeof this.connect === 'function'
@@ -68,12 +68,14 @@ export class ConnectBase {
6868
this.stateSubscription = this.store.subscribe(() => this.resetState());
6969

7070
Promise.resolve().then(() => {
71-
this.formSubscription = (<any>this.form.valueChanges).debounceTime(0).subscribe(values => this.publish(values));
71+
this.formSubscription = (<any>this.form.valueChanges)
72+
.debounceTime(0)
73+
.subscribe((values: any) => this.publish(values));
7274
});
7375
});
7476
}
7577

76-
private descendants(path: Array<string>, formElement): Array<ControlPair> {
78+
private descendants(path: Array<string>, formElement: any): Array<ControlPair> {
7779
const pairs = new Array<ControlPair>();
7880

7981
if (formElement instanceof FormArray) {
@@ -122,7 +124,7 @@ export class ConnectBase {
122124
});
123125
}
124126

125-
private publish(value) {
127+
private publish(value: any) {
126128
this.store.valueChanged(this.path, this.form, value);
127129
}
128130

source/connect-reactive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ConnectBase} from './connect-base';
1010
// For reactive forms (without implicit NgForm)
1111
@Directive({ selector: 'form[connect][formGroup]' })
1212
export class ReactiveConnect extends ConnectBase {
13-
@Input('formGroup') form;
13+
@Input('formGroup') form: any;
1414

1515
constructor(
1616
protected store: FormStore

source/form-reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {FORM_CHANGED} from './form-store';
77
import {State} from './state';
88

99
export const defaultFormReducer = <RootState>(initialState?: RootState | Iterable.Keyed<string, any>) => {
10-
const reducer = (state: RootState | Iterable.Keyed<string, any> = initialState, action: Action & {payload?}) => {
10+
const reducer = (state: RootState | Iterable.Keyed<string, any> | undefined = initialState, action: Action & {payload?: any}) => {
1111
switch (action.type) {
1212
case FORM_CHANGED:
1313
return State.assign(

source/form-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Action, Unsubscribe} from 'redux';
88

99
export interface AbstractStore<RootState> {
1010
/// Dispatch an action
11-
dispatch(action: Action & {payload}): void;
11+
dispatch(action: Action & {payload: any}): void;
1212

1313
/// Retrieve the current application state
1414
getState(): RootState;
@@ -34,7 +34,7 @@ export class FormStore {
3434
return this.store.getState();
3535
}
3636

37-
subscribe(fn: (state) => void): Unsubscribe {
37+
subscribe(fn: (state: any) => void): Unsubscribe {
3838
return this.store.subscribe(() => fn(this.getState()));
3939
}
4040

source/shims.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export function controlPath(name: string, parent: ControlContainer): string[] {
1414
}
1515

1616
export function selectValueAccessor(
17-
dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor {
17+
dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor | null {
1818
if (!valueAccessors) return null;
1919

20-
let defaultAccessor: ControlValueAccessor;
21-
let builtinAccessor: ControlValueAccessor;
22-
let customAccessor: ControlValueAccessor;
20+
let defaultAccessor: ControlValueAccessor | null = null;
21+
let builtinAccessor: ControlValueAccessor | null = null;
22+
let customAccessor: ControlValueAccessor | null = null;
2323
valueAccessors.forEach((v: ControlValueAccessor) => {
2424
if (v.constructor === DefaultValueAccessor) {
2525
defaultAccessor = v;

0 commit comments

Comments
 (0)