From ef305af977eca1b72fea1fdeeaf8ab54ca6cd88e Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Sat, 9 Apr 2016 22:58:27 +0900 Subject: [PATCH] fix(typings): make an exported function's destructuring signature explicitly. --- src/observable/BoundCallbackObservable.ts | 14 +++++++++-- src/observable/BoundNodeCallbackObservable.ts | 14 +++++++++-- src/observable/EmptyObservable.ts | 7 +++++- src/observable/ErrorObservable.ts | 8 ++++++- src/observable/PromiseObservable.ts | 14 +++++++++-- src/observable/SubscribeOnObservable.ts | 8 ++++++- src/operator/bufferTime.ts | 10 ++++++-- src/operator/expand.ts | 12 ++++++++-- src/operator/observeOn.ts | 5 ++-- src/operator/throttleTime.ts | 7 +++++- src/operator/windowTime.ts | 23 +++++++++++++++---- 11 files changed, 101 insertions(+), 21 deletions(-) diff --git a/src/observable/BoundCallbackObservable.ts b/src/observable/BoundCallbackObservable.ts index d39ee4d494..8d1633781d 100644 --- a/src/observable/BoundCallbackObservable.ts +++ b/src/observable/BoundCallbackObservable.ts @@ -138,11 +138,21 @@ function dispatch(state: { source: BoundCallbackObservable, subscriber: Su self.add(subject.subscribe(subscriber)); } -function dispatchNext({ value, subject }) { +interface DispatchNextArg { + subject: AsyncSubject; + value: T; +} +function dispatchNext(arg: DispatchNextArg) { + const { value, subject } = arg; subject.next(value); subject.complete(); } -function dispatchError({ err, subject }) { +interface DispatchErrorArg { + subject: AsyncSubject; + err: any; +} +function dispatchError(arg: DispatchErrorArg) { + const { err, subject } = arg; subject.error(err); } diff --git a/src/observable/BoundNodeCallbackObservable.ts b/src/observable/BoundNodeCallbackObservable.ts index ad3249c6c8..a70e7f671b 100644 --- a/src/observable/BoundNodeCallbackObservable.ts +++ b/src/observable/BoundNodeCallbackObservable.ts @@ -135,11 +135,21 @@ function dispatch(state: { source: BoundNodeCallbackObservable, subscriber self.add(subject.subscribe(subscriber)); } -function dispatchNext({ value, subject }) { +interface DispatchNextArg { + subject: AsyncSubject; + value: T; +} +function dispatchNext(arg: DispatchNextArg) { + const { value, subject } = arg; subject.next(value); subject.complete(); } -function dispatchError({ err, subject }) { +interface DispatchErrorArg { + subject: AsyncSubject; + err: any; +} +function dispatchError(arg: DispatchErrorArg) { + const { err, subject } = arg; subject.error(err); } diff --git a/src/observable/EmptyObservable.ts b/src/observable/EmptyObservable.ts index 21e372b5bf..6a58285838 100644 --- a/src/observable/EmptyObservable.ts +++ b/src/observable/EmptyObservable.ts @@ -3,6 +3,10 @@ import {Subscriber} from '../Subscriber'; import {Observable} from '../Observable'; import {TeardownLogic} from '../Subscription'; +export interface DispatchArg { + subscriber: Subscriber; +} + /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} @@ -51,7 +55,8 @@ export class EmptyObservable extends Observable { return new EmptyObservable(scheduler); } - static dispatch({ subscriber }) { + static dispatch(arg: DispatchArg) { + const { subscriber } = arg; subscriber.complete(); } diff --git a/src/observable/ErrorObservable.ts b/src/observable/ErrorObservable.ts index 32285c154b..0d63d27c25 100644 --- a/src/observable/ErrorObservable.ts +++ b/src/observable/ErrorObservable.ts @@ -2,6 +2,11 @@ import {Scheduler} from '../Scheduler'; import {Observable} from '../Observable'; import {TeardownLogic} from '../Subscription'; +export interface DispatchArg { + error: any; + subscriber: any; +} + /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} @@ -53,7 +58,8 @@ export class ErrorObservable extends Observable { return new ErrorObservable(error, scheduler); } - static dispatch({ error, subscriber }) { + static dispatch(arg: DispatchArg) { + const { error, subscriber } = arg; subscriber.error(error); } diff --git a/src/observable/PromiseObservable.ts b/src/observable/PromiseObservable.ts index 99aaa94d07..c8d81a6574 100644 --- a/src/observable/PromiseObservable.ts +++ b/src/observable/PromiseObservable.ts @@ -88,14 +88,24 @@ export class PromiseObservable extends Observable { } } -function dispatchNext({ value, subscriber }) { +interface DispatchNextArg { + subscriber: Subscriber; + value: T; +} +function dispatchNext(arg: DispatchNextArg) { + const { value, subscriber } = arg; if (!subscriber.isUnsubscribed) { subscriber.next(value); subscriber.complete(); } } -function dispatchError({ err, subscriber }) { +interface DispatchErrorArg { + subscriber: Subscriber; + err: any; +} +function dispatchError(arg: DispatchErrorArg) { + const { err, subscriber } = arg; if (!subscriber.isUnsubscribed) { subscriber.error(err); } diff --git a/src/observable/SubscribeOnObservable.ts b/src/observable/SubscribeOnObservable.ts index d497859d98..9dac992115 100644 --- a/src/observable/SubscribeOnObservable.ts +++ b/src/observable/SubscribeOnObservable.ts @@ -5,6 +5,11 @@ import {Observable} from '../Observable'; import {asap} from '../scheduler/asap'; import {isNumeric} from '../util/isNumeric'; +export interface DispatchArg { + source: Observable; + subscriber: Subscriber; +} + /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} @@ -15,7 +20,8 @@ export class SubscribeOnObservable extends Observable { return new SubscribeOnObservable(source, delay, scheduler); } - static dispatch({ source, subscriber }): Subscription { + static dispatch(arg: DispatchArg): Subscription { + const { source, subscriber } = arg; return source.subscribe(subscriber); } diff --git a/src/operator/bufferTime.ts b/src/operator/bufferTime.ts index cd74de5878..d8531e58a7 100644 --- a/src/operator/bufferTime.ts +++ b/src/operator/bufferTime.ts @@ -152,16 +152,22 @@ function dispatchBufferTimeSpanOnly(state: any) { } } +interface DispatchArg { + subscriber: BufferTimeSubscriber; + buffer: Array; +} + function dispatchBufferCreation(state: CreationState) { const { bufferCreationInterval, bufferTimeSpan, subscriber, scheduler } = state; const buffer = subscriber.openBuffer(); const action = >>this; if (!subscriber.isUnsubscribed) { - action.add(scheduler.schedule(dispatchBufferClose, bufferTimeSpan, { subscriber, buffer })); + action.add(scheduler.schedule>(dispatchBufferClose, bufferTimeSpan, { subscriber, buffer })); action.schedule(state, bufferCreationInterval); } } -function dispatchBufferClose({ subscriber, buffer }) { +function dispatchBufferClose(arg: DispatchArg) { + const { subscriber, buffer } = arg; subscriber.closeBuffer(buffer); } diff --git a/src/operator/expand.ts b/src/operator/expand.ts index 8b4b6defc6..31884123f0 100644 --- a/src/operator/expand.ts +++ b/src/operator/expand.ts @@ -43,6 +43,13 @@ export class ExpandOperator implements Operator { } } +interface DispatchArg { + subscriber: ExpandSubscriber; + result: Observable; + value: any; + index: number; +} + /** * We need this JSDoc comment for affecting ESDoc. * @ignore @@ -64,7 +71,8 @@ export class ExpandSubscriber extends OuterSubscriber { } } - private static dispatch({subscriber, result, value, index}): void { + private static dispatch(arg: DispatchArg): void { + const {subscriber, result, value, index} = arg; subscriber.subscribeToProjection(result, value, index); } @@ -85,7 +93,7 @@ export class ExpandSubscriber extends OuterSubscriber { } else if (!this.scheduler) { this.subscribeToProjection(result, value, index); } else { - const state = { subscriber: this, result, value, index }; + const state: DispatchArg = { subscriber: this, result, value, index }; this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state)); } } else { diff --git a/src/operator/observeOn.ts b/src/operator/observeOn.ts index f28ef02f66..21ba3404bb 100644 --- a/src/operator/observeOn.ts +++ b/src/operator/observeOn.ts @@ -37,7 +37,8 @@ export class ObserveOnOperator implements Operator { * @extends {Ignored} */ export class ObserveOnSubscriber extends Subscriber { - static dispatch({ notification, destination }) { + static dispatch(arg: ObserveOnMessage) { + const { notification, destination } = arg; notification.observe(destination); } @@ -66,7 +67,7 @@ export class ObserveOnSubscriber extends Subscriber { } } -class ObserveOnMessage { +export class ObserveOnMessage { constructor(public notification: Notification, public destination: PartialObserver) { } diff --git a/src/operator/throttleTime.ts b/src/operator/throttleTime.ts index 1b6a51e4a5..9c857f0953 100644 --- a/src/operator/throttleTime.ts +++ b/src/operator/throttleTime.ts @@ -60,6 +60,11 @@ class ThrottleTimeSubscriber extends Subscriber { } } -function dispatchNext({ subscriber }) { +interface DispatchArg { + subscriber: ThrottleTimeSubscriber; +} + +function dispatchNext(arg: DispatchArg) { + const { subscriber } = arg; subscriber.clearThrottle(); } diff --git a/src/operator/windowTime.ts b/src/operator/windowTime.ts index 5abf5783c5..60c1488d43 100644 --- a/src/operator/windowTime.ts +++ b/src/operator/windowTime.ts @@ -2,6 +2,7 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {Observable} from '../Observable'; import {Subject} from '../Subject'; +import {Subscription} from '../Subscription'; import {Scheduler} from '../Scheduler'; import {Action} from '../scheduler/Action'; import {async} from '../scheduler/async'; @@ -79,12 +80,12 @@ class WindowTimeOperator implements Operator> { } } -type CreationState = { +interface CreationState { windowTimeSpan: number; windowCreationInterval: number; subscriber: WindowTimeSubscriber; scheduler: Scheduler; -}; +} /** * We need this JSDoc comment for affecting ESDoc. @@ -173,18 +174,30 @@ function dispatchWindowTimeSpanOnly(state: TimeSpanOnlyState) { (this).schedule(state, windowTimeSpan); } +interface Context { + action: Action>; + subscription: Subscription; +} + +interface DispatchArg { + subscriber: WindowTimeSubscriber; + window: Subject; + context: Context; +} + function dispatchWindowCreation(state: CreationState) { let { windowTimeSpan, subscriber, scheduler, windowCreationInterval } = state; let window = subscriber.openWindow(); let action = >>this; - let context = { action, subscription: null }; - const timeSpanState = { subscriber, window, context }; + let context: Context = { action, subscription: null }; + const timeSpanState: DispatchArg = { subscriber, window, context }; context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState); action.add(context.subscription); action.schedule(state, windowCreationInterval); } -function dispatchWindowClose({ subscriber, window, context }) { +function dispatchWindowClose(arg: DispatchArg) { + const { subscriber, window, context } = arg; if (context && context.action && context.subscription) { context.action.remove(context.subscription); }