Skip to content

Commit

Permalink
fix: add typescript unused checks (angular-redux#32)
Browse files Browse the repository at this point in the history
The library currently does not work in projects that have noUnusedLocals and noUnusedParameters set inside of tsconfig.json. This should bring the project into compliance with those rules.
  • Loading branch information
smithad15 committed Jul 9, 2018
1 parent 51abd6b commit 65c4229
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 65 deletions.
3 changes: 0 additions & 3 deletions packages/form/source/compose-reducers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {Reducer, Action} from 'redux';

import {Iterable} from 'immutable';

import {FormException} from './form-exception';
import {State} from './state';

export const composeReducers =
Expand Down
2 changes: 0 additions & 2 deletions packages/form/source/configure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {FormControl} from '@angular/forms';

import {
Action,
Store,
Expand Down
15 changes: 5 additions & 10 deletions packages/form/source/connect-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import {
NG_VALUE_ACCESSOR,
AbstractControl,
DefaultValueAccessor,
FormArray,
FormArrayName,
FormControl,
Expand All @@ -37,8 +36,6 @@ import {
} from '@angular/forms';
import {Unsubscribe} from 'redux';

import {Subscription} from 'rxjs';

import {ConnectBase} from './connect-base';
import {FormStore} from './form-store';
import {State} from './state';
Expand All @@ -62,8 +59,6 @@ export class ConnectArrayTemplate {
export class ConnectArray extends ControlContainer implements OnInit {
private stateSubscription: Unsubscribe;

private formSubscription: Subscription;

private array = new FormArray([]);

private valueAccessor: ControlValueAccessor;
Expand Down Expand Up @@ -180,8 +175,8 @@ export class ConnectArray extends ControlContainer implements OnInit {
}

private registerInternals(array) {
array.registerControl = c => {};
array.registerOnChange = fn => {};
array.registerControl = () => {};
array.registerOnChange = () => {};

Object.defineProperties(this, {
_rawValidators: {
Expand Down Expand Up @@ -251,7 +246,7 @@ export class ConnectArray extends ControlContainer implements OnInit {
return array;
}

const associate = <T>(value): FormGroup => {
const associate = (value): FormGroup => {
const group = new FormGroup({});
group.setParent(parent);

Expand Down Expand Up @@ -286,8 +281,8 @@ export class ConnectArray extends ControlContainer implements OnInit {
private simpleAccessor() {
return {
writeValue: value => this.control.setValue(value),
registerOnChange(fn) {},
registerOnTouched(fn) {}
registerOnChange() {},
registerOnTouched() {}
};
}
}
13 changes: 3 additions & 10 deletions packages/form/source/connect-base.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {
Directive,
Input,
} from '@angular/core';
import { Input } from '@angular/core';

import {
AbstractControl,
FormControl,
FormGroup,
FormArray,
NgForm,
NgControl,
} from '@angular/forms';

Expand All @@ -18,7 +14,6 @@ import { Unsubscribe } from 'redux';

import 'rxjs/add/operator/debounceTime';

import { FormException } from './form-exception';
import { FormStore } from './form-store';
import { State } from './state';

Expand Down Expand Up @@ -66,13 +61,11 @@ export class ConnectBase {
}
}

private ngAfterContentInit() {
ngAfterContentInit() {
Promise.resolve().then(() => {
this.resetState();

this.stateSubscription = this.store.subscribe(state => {
this.resetState();
});
this.stateSubscription = this.store.subscribe(() => this.resetState());

Promise.resolve().then(() => {
this.formSubscription = (<any>this.form.valueChanges).debounceTime(0).subscribe(values => this.publish(values));
Expand Down
4 changes: 0 additions & 4 deletions packages/form/source/connect-reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import {
Input,
} from '@angular/core';

import {
NgForm
} from '@angular/forms';

import {FormStore} from './form-store';

import {ConnectBase} from './connect-base';
Expand Down
11 changes: 2 additions & 9 deletions packages/form/source/connect.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import {
Directive,
Input,
} from '@angular/core';

import {
NgForm
} from '@angular/forms';
import { Directive } from '@angular/core';

import { NgForm } from '@angular/forms';

import {FormStore} from './form-store';
import {State} from './state';
import {ConnectBase} from './connect-base';


Expand Down
15 changes: 3 additions & 12 deletions packages/form/source/form-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import {
Iterable,
Map,
fromJS
} from 'immutable';
import {Iterable} from 'immutable';

import {Action, Reducer} from 'redux';
import {Action} from 'redux';

import {FormException} from './form-exception';

import {
FORM_CHANGED,
FormStore,
} from './form-store';
import {FORM_CHANGED} from './form-store';

import {State} from './state';

Expand Down
2 changes: 1 addition & 1 deletion packages/form/source/form-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {NgForm} from '@angular/forms';

import {NgRedux} from '@angular-redux/store';

import {Action, Store, Unsubscribe} from 'redux';
import {Action, Unsubscribe} from 'redux';

export interface AbstractStore<RootState> {
/// Dispatch an action
Expand Down
18 changes: 5 additions & 13 deletions packages/form/source/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ export abstract class State {
}

static assign<State>(state: State, path: string[], value?) {
interface Modifiable {
key: string;
operations: {
clone<T>(): T;
update<T, V>(key: number | string, value: V): T;
};
};

const operations = State.inspect(state);

if (path.length === 0) {
Expand Down Expand Up @@ -157,7 +149,7 @@ export abstract class State {
}
},
// Merge
(parent, key: number | string | string[], value: K, setter: (v: K) => K) => {
(parent, key: number | string | string[], value: K) => {
if (key) {
return parent.mergeDeepIn(Array.isArray(key) ? key : [key], value);
}
Expand Down Expand Up @@ -185,7 +177,7 @@ export abstract class State {
},

// Merge
(parent, key: number | string, value: K, setter: (v: K) => K) => {
(parent, _, value: K, setter: (v: K) => K) => {
setter(parent.concat(value));
return parent;
},
Expand All @@ -210,7 +202,7 @@ export abstract class State {
},

// Merge
(parent: Map<string, any>, key: number | string, value: K, setter: (v: K) => K) => {
(parent: Map<string, any>, _, value: K) => {
const m = new Map<string, any>(<any> value);
m.forEach((value, key) => parent.set(key, value));
return parent;
Expand Down Expand Up @@ -238,7 +230,7 @@ export abstract class State {
},

// Merge
(parent: Set<any>, key: number | string, value, setter: (v: K) => K) => {
(parent: Set<any>, _, value) => {
for (const element of value) {
parent.add(element);
}
Expand Down Expand Up @@ -274,7 +266,7 @@ export abstract class State {
}
return Object.assign(parent, value);
},
(parent, key: number | string, value: K, setter: (v: K) => K) => {
(parent, _, value: K) => {
for (const k of Object.keys(value)) {
parent[k] = value[k];
}
Expand Down
4 changes: 3 additions & 1 deletion packages/form/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"inlineSourceMap": true,
"declaration": true,
"outDir": "dist",
"rootDir": ""
"rootDir": "",
"noUnusedLocals": true,
"noUnusedParameters": true
},
"awesomeTypescriptLoaderOptions": {
"emitRequireType": false,
Expand Down

0 comments on commit 65c4229

Please sign in to comment.