Skip to content

Commit

Permalink
feat(TypeScript): enable ' --noUnusedLocals' option
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuharuohzeki committed Nov 4, 2016
1 parent b5fb259 commit edfc143
Show file tree
Hide file tree
Showing 35 changed files with 166 additions and 140 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"copy_src_cjs": "mkdirp ./dist/cjs/src && shx cp -r ./src/* ./dist/cjs/src",
"copy_src_es6": "mkdirp ./dist/es6/src && shx cp -r ./src/* ./dist/es6/src",
"commit": "git-cz",
"compile_dist_cjs": "tsc ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_module_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom ",
"compile_dist_es6_for_docs": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts ./dist/es6/src/MiscJSDoc.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_dist_cjs": "tsc ./dist/cjs/src/Rx.ts ./dist/cjs/src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --sourceMap --outDir ./dist/cjs --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node",
"compile_module_es6": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES5 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom ",
"compile_dist_es6_for_docs": "tsc ./dist/es6/src/Rx.ts ./dist/es6/src/add/observable/of.ts ./dist/es6/src/MiscJSDoc.ts -m es2015 --sourceMap --outDir ./dist/es6 --target ES6 -d --diagnostics --pretty --noImplicitAny --noImplicitReturns --noUnusedLocals --suppressImplicitAnyIndexErrors --moduleResolution node",
"cover": "shx rm -rf dist/cjs && tsc src/Rx.ts src/add/observable/of.ts -m commonjs --lib es5,es2015.iterable,es2015.collection,es2015.promise,dom --outDir dist/cjs --sourceMap --target ES5 -d && nyc --reporter=lcov --reporter=html --exclude=spec/support/**/* --exclude=spec-js/**/* --exclude=node_modules mocha --opts spec/support/default.opts spec-js",
"decision_tree_widget": "cd doc/decision-tree-widget && npm run build && cd ../..",
"doctoc": "doctoc CONTRIBUTING.md",
Expand Down
3 changes: 2 additions & 1 deletion src/Operator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Observable } from './Observable';
import { Subscriber } from './Subscriber';
import { TeardownLogic } from './Subscription';

export interface Operator<T, R> {
call(subscriber: Subscriber<R>, source: any): TeardownLogic;
call(subscriber: Subscriber<R>, source: Observable<T>): TeardownLogic;
}
7 changes: 6 additions & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ import { $$observable as observable } from './symbol/observable';
* @property {Scheduler} animationFrame Schedules work with `requestAnimationFrame`.
* Use this for synchronizing with the platform's painting
*/
let Scheduler = {
let Scheduler: {
asap: AsapScheduler;
queue: QueueScheduler;
animationFrame: AnimationFrameScheduler;
async: AsyncScheduler;
} = {
asap,
queue,
animationFrame,
Expand Down
3 changes: 2 additions & 1 deletion src/observable/ArrayLikeObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class ArrayLikeObservable<T> extends Observable<T> {

protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {
let index = 0;
const { arrayLike, scheduler } = this;
const arrayLike = this.arrayLike;
const scheduler = this.scheduler;
const length = arrayLike.length;

if (scheduler) {
Expand Down
5 changes: 3 additions & 2 deletions src/observable/BoundCallbackObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ export class BoundCallbackObservable<T> extends Observable<T> {
if (!subject) {
subject = this.subject = new AsyncSubject<T>();
const handler = function handlerFn(...innerArgs: any[]) {
const source = (<any>handlerFn).source;
const { selector, subject } = source;
const source: BoundCallbackObservable<T> = (<any>handlerFn).source;
const { subject } = source;
const selector = source.selector;
if (selector) {
const result = tryCatch(selector).apply(this, innerArgs);
if (result === errorObject) {
Expand Down
5 changes: 3 additions & 2 deletions src/observable/BoundNodeCallbackObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
if (!subject) {
subject = this.subject = new AsyncSubject<T>();
const handler = function handlerFn(...innerArgs: any[]) {
const source = (<any>handlerFn).source;
const { selector, subject } = source;
const source: BoundNodeCallbackObservable<T> = (<any>handlerFn).source;
const { subject } = source;
const selector = source.selector;
const err = innerArgs.shift();

if (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/observable/ConnectableObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class RefCountOperator<T> implements Operator<T, T> {
constructor(private connectable: ConnectableObservable<T>) {
}
call(subscriber: Subscriber<T>, source: any): TeardownLogic {

const { connectable } = this;
const connectable = this.connectable;
(<any> connectable)._refCount++;

const refCounter = new RefCountSubscriber(subscriber, connectable);
Expand Down
5 changes: 3 additions & 2 deletions src/observable/ForkJoinObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {
private haveValues = 0;

constructor(destination: Subscriber<T>,
private sources: Array<SubscribableOrPromise<any>>,
sources: Array<SubscribableOrPromise<any>>,
private resultSelector?: (...values: Array<any>) => T) {
super(destination);

Expand Down Expand Up @@ -117,7 +117,8 @@ class ForkJoinSubscriber<T> extends OuterSubscriber<T, T> {

notifyComplete(innerSub: InnerSubscriber<T, T>): void {
const destination = this.destination;
const { haveValues, resultSelector, values } = this;
const { haveValues, values } = this;
const resultSelector = this.resultSelector;
const len = values.length;

if (!(<any>innerSub)._hasValue) {
Expand Down
8 changes: 6 additions & 2 deletions src/observable/IfObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class IfObservable<T, R> extends Observable<T> {
}

protected _subscribe(subscriber: Subscriber<T|R>): TeardownLogic {
const { condition, thenSource, elseSource } = this;
const condition = this.condition;
const thenSource = this.thenSource;
const elseSource = this.elseSource;

return new IfSubscriber(subscriber, condition, thenSource, elseSource);
}
Expand All @@ -40,7 +42,9 @@ class IfSubscriber<T, R> extends OuterSubscriber<T, T> {
}

private tryIf(): void {
const { condition, thenSource, elseSource } = this;
const condition = this.condition;
const thenSource = this.thenSource;
const elseSource = this.elseSource;

let result: boolean;
try {
Expand Down
3 changes: 2 additions & 1 deletion src/observable/IteratorObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class IteratorObservable<T> extends Observable<T> {
protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {

let index = 0;
const { iterator, scheduler } = this;
const iterator = this.iterator;
const scheduler = this.scheduler;

if (scheduler) {
return scheduler.schedule(IteratorObservable.dispatch, 0, {
Expand Down
187 changes: 94 additions & 93 deletions src/observable/PairsObservable.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,95 @@
import { Scheduler } from '../Scheduler';
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { TeardownLogic } from '../Subscription';

interface PairsContext<T> {
obj: Object;
keys: Array<string>;
length: number;
index: number;
subscriber: Subscriber<Array<string | T>>;
}

function dispatch<T>(state: PairsContext<T>) {
const {obj, keys, length, index, subscriber} = state;

if (index === length) {
subscriber.complete();
return;
}

const key = keys[index];
subscriber.next([key, obj[key]]);

state.index = index + 1;

(<any> this).schedule(state);
}

/**
* We need this JSDoc comment for affecting ESDoc.
* @extends {Ignored}
* @hide true
*/
export class PairsObservable<T> extends Observable<Array<string | T>> {
private keys: Array<string>;

/**
* Convert an object into an observable sequence of [key, value] pairs
* using an optional Scheduler to enumerate the object.
*
* @example <caption>Converts a javascript object to an Observable</caption>
* var obj = {
* foo: 42,
* bar: 56,
* baz: 78
* };
*
* var source = Rx.Observable.pairs(obj);
*
* var subscription = source.subscribe(
* function (x) {
* console.log('Next: %s', x);
* },
* function (err) {
* console.log('Error: %s', err);
* },
* function () {
* console.log('Completed');
* });
*
* @param {Object} obj The object to inspect and turn into an
* Observable sequence.
* @param {Scheduler} [scheduler] An optional Scheduler to run the
* enumeration of the input sequence on.
* @returns {(Observable<Array<string | T>>)} An observable sequence of
* [key, value] pairs from the object.
*/
static create<T>(obj: Object, scheduler?: Scheduler): Observable<Array<string | T>> {
return new PairsObservable<T>(obj, scheduler);
}

constructor(private obj: Object, private scheduler?: Scheduler) {
super();
this.keys = Object.keys(obj);
}

protected _subscribe(subscriber: Subscriber<Array<string | T>>): TeardownLogic {
const {keys, scheduler} = this;
const length = keys.length;

if (scheduler) {
return scheduler.schedule(dispatch, 0, {
obj: this.obj, keys, length, index: 0, subscriber
});
} else {
for (let idx = 0; idx < length; idx++) {
const key = keys[idx];
subscriber.next([key, this.obj[key]]);
}
subscriber.complete();
}
}
import { Scheduler } from '../Scheduler';
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { TeardownLogic } from '../Subscription';

interface PairsContext<T> {
obj: Object;
keys: Array<string>;
length: number;
index: number;
subscriber: Subscriber<Array<string | T>>;
}

function dispatch<T>(state: PairsContext<T>) {
const {obj, keys, length, index, subscriber} = state;

if (index === length) {
subscriber.complete();
return;
}

const key = keys[index];
subscriber.next([key, obj[key]]);

state.index = index + 1;

(<any> this).schedule(state);
}

/**
* We need this JSDoc comment for affecting ESDoc.
* @extends {Ignored}
* @hide true
*/
export class PairsObservable<T> extends Observable<Array<string | T>> {
private keys: Array<string>;

/**
* Convert an object into an observable sequence of [key, value] pairs
* using an optional Scheduler to enumerate the object.
*
* @example <caption>Converts a javascript object to an Observable</caption>
* var obj = {
* foo: 42,
* bar: 56,
* baz: 78
* };
*
* var source = Rx.Observable.pairs(obj);
*
* var subscription = source.subscribe(
* function (x) {
* console.log('Next: %s', x);
* },
* function (err) {
* console.log('Error: %s', err);
* },
* function () {
* console.log('Completed');
* });
*
* @param {Object} obj The object to inspect and turn into an
* Observable sequence.
* @param {Scheduler} [scheduler] An optional Scheduler to run the
* enumeration of the input sequence on.
* @returns {(Observable<Array<string | T>>)} An observable sequence of
* [key, value] pairs from the object.
*/
static create<T>(obj: Object, scheduler?: Scheduler): Observable<Array<string | T>> {
return new PairsObservable<T>(obj, scheduler);
}

constructor(private obj: Object, private scheduler?: Scheduler) {
super();
this.keys = Object.keys(obj);
}

protected _subscribe(subscriber: Subscriber<Array<string | T>>): TeardownLogic {
const keys = this.keys;
const scheduler = this.scheduler;
const length = keys.length;

if (scheduler) {
return scheduler.schedule(dispatch, 0, {
obj: this.obj, keys, length, index: 0, subscriber
});
} else {
for (let idx = 0; idx < length; idx++) {
const key = keys[idx];
subscriber.next([key, this.obj[key]]);
}
subscriber.complete();
}
}
}
3 changes: 2 additions & 1 deletion src/observable/UsingObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class UsingObservable<T> extends Observable<T> {
}

protected _subscribe(subscriber: Subscriber<T>): TeardownLogic {
const { resourceFactory, observableFactory } = this;
const resourceFactory = this.resourceFactory;
const observableFactory = this.observableFactory;

let resource: AnonymousSubscription;

Expand Down
4 changes: 3 additions & 1 deletion src/operator/bufferCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class BufferCountSubscriber<T> extends Subscriber<T> {

protected _next(value: T) {
const count = this.count++;
const { destination, bufferSize, startBufferEvery, buffers } = this;
const { destination, buffers } = this;
const bufferSize = this.bufferSize;
const startBufferEvery = this.startBufferEvery;
const startOn = (startBufferEvery == null) ? bufferSize : startBufferEvery;

if (count % startOn === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/operator/bufferTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class BufferTimeSubscriber<T> extends Subscriber<T> {

constructor(destination: Subscriber<T[]>,
private bufferTimeSpan: number,
private bufferCreationInterval: number,
bufferCreationInterval: number,
private maxBufferSize: number,
private scheduler: Scheduler) {
super(destination);
Expand Down
2 changes: 1 addition & 1 deletion src/operator/bufferToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BufferToggleSubscriber<T, O> extends OuterSubscriber<T, O> {
private contexts: Array<BufferContext<T>> = [];

constructor(destination: Subscriber<T[]>,
private openings: SubscribableOrPromise<O>,
openings: SubscribableOrPromise<O>,
private closingSelector: (value: O) => SubscribableOrPromise<any> | void) {
super(destination);
this.add(subscribeToResult(this, openings));
Expand Down
2 changes: 1 addition & 1 deletion src/operator/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function concatStatic<T, R>(...observables: (ObservableInput<any> | Sched
* @name concat
* @owner Observable
*/
export function concatStatic<T, R>(...observables: Array<ObservableInput<any> | Scheduler>): Observable<R> {
export function concatStatic<R>(...observables: Array<ObservableInput<any> | Scheduler>): Observable<R> {
let scheduler: Scheduler = null;
let args = <any[]>observables;
if (isScheduler(args[observables.length - 1])) {
Expand Down
6 changes: 3 additions & 3 deletions src/operator/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
}));
}

private scheduleNotification(notification: Notification<any>): void {
private scheduleNotification(notification: Notification<T>): void {
if (this.errored === true) {
return;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
}

class DelayMessage<T> {
constructor(private time: number,
private notification: any) {
constructor(public time: number,
public notification: Notification<T>) {
}
}
3 changes: 2 additions & 1 deletion src/operator/exhaustMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class SwitchFirstMapSubscriber<T, I, R> extends OuterSubscriber<T, I> {
notifyNext(outerValue: T, innerValue: I,
outerIndex: number, innerIndex: number,
innerSub: InnerSubscriber<T, I>): void {
const { resultSelector, destination } = this;
const destination = this.destination;
const resultSelector = this.resultSelector;
if (resultSelector) {
this.trySelectResult(outerValue, innerValue, outerIndex, innerIndex);
} else {
Expand Down
Loading

0 comments on commit edfc143

Please sign in to comment.