Skip to content

Commit

Permalink
fix(TypeScript): interfaces that accepted Scheduler now accept `ISc…
Browse files Browse the repository at this point in the history
…heduler` interface

this should be a non-breaking change. It just makes sense to accept a minimal interface here rather than a full-on class
  • Loading branch information
benlesh committed Dec 23, 2016
1 parent 6922b16 commit a0d28a8
Show file tree
Hide file tree
Showing 40 changed files with 302 additions and 298 deletions.
4 changes: 2 additions & 2 deletions src/ReplaySubject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subject } from './Subject';
import { Scheduler } from './Scheduler';
import { IScheduler } from './Scheduler';
import { queue } from './scheduler/queue';
import { Subscriber } from './Subscriber';
import { Subscription } from './Subscription';
Expand All @@ -16,7 +16,7 @@ export class ReplaySubject<T> extends Subject<T> {

constructor(bufferSize: number = Number.POSITIVE_INFINITY,
windowTime: number = Number.POSITIVE_INFINITY,
private scheduler?: Scheduler) {
private scheduler?: IScheduler) {
super();
this._bufferSize = bufferSize < 1 ? 1 : bufferSize;
this._windowTime = windowTime < 1 ? 1 : windowTime;
Expand Down
6 changes: 5 additions & 1 deletion src/Scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Action } from './scheduler/Action';
import { Subscription } from './Subscription';

export interface IScheduler {
now(): number;
schedule<T>(work: (this: Action<T>, state?: T) => void, delay?: number, state?: T): Subscription;
}
/**
* An execution context and a data structure to order tasks and schedule their
* execution. Provides a notion of (potentially virtual) time, through the
Expand All @@ -17,7 +21,7 @@ import { Subscription } from './Subscription';
*
* @class Scheduler
*/
export class Scheduler {
export class Scheduler implements IScheduler {

public static now: () => number = Date.now ? Date.now : () => +new Date();

Expand Down
6 changes: 3 additions & 3 deletions src/observable/ArrayLikeObservable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scheduler } from '../Scheduler';
import { IScheduler } from '../Scheduler';
import { Observable } from '../Observable';
import { ScalarObservable } from './ScalarObservable';
import { EmptyObservable } from './EmptyObservable';
Expand All @@ -12,7 +12,7 @@ import { TeardownLogic } from '../Subscription';
*/
export class ArrayLikeObservable<T> extends Observable<T> {

static create<T>(arrayLike: ArrayLike<T>, scheduler?: Scheduler): Observable<T> {
static create<T>(arrayLike: ArrayLike<T>, scheduler?: IScheduler): Observable<T> {
const length = arrayLike.length;
if (length === 0) {
return new EmptyObservable<T>();
Expand Down Expand Up @@ -45,7 +45,7 @@ export class ArrayLikeObservable<T> extends Observable<T> {
// value used if Array has one value and _isScalar
private value: any;

constructor(private arrayLike: ArrayLike<T>, private scheduler?: Scheduler) {
constructor(private arrayLike: ArrayLike<T>, private scheduler?: IScheduler) {
super();
if (!scheduler && arrayLike.length === 1) {
this._isScalar = true;
Expand Down
30 changes: 15 additions & 15 deletions src/observable/ArrayObservable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scheduler } from '../Scheduler';
import { IScheduler } from '../Scheduler';
import { Observable } from '../Observable';
import { ScalarObservable } from './ScalarObservable';
import { EmptyObservable } from './EmptyObservable';
Expand All @@ -13,17 +13,17 @@ import { TeardownLogic } from '../Subscription';
*/
export class ArrayObservable<T> extends Observable<T> {

static create<T>(array: T[], scheduler?: Scheduler): Observable<T> {
static create<T>(array: T[], scheduler?: IScheduler): Observable<T> {
return new ArrayObservable(array, scheduler);
}

static of<T>(item1: T, scheduler?: Scheduler): Observable<T>;
static of<T>(item1: T, item2: T, scheduler?: Scheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, scheduler?: Scheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, scheduler?: Scheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: Scheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: Scheduler): Observable<T>;
static of<T>(...array: Array<T | Scheduler>): Observable<T>;
static of<T>(item1: T, scheduler?: IScheduler): Observable<T>;
static of<T>(item1: T, item2: T, scheduler?: IScheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, scheduler?: IScheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, scheduler?: IScheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: IScheduler): Observable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: IScheduler): Observable<T>;
static of<T>(...array: Array<T | IScheduler>): Observable<T>;
/**
* Creates an Observable that emits some values you specify as arguments,
* immediately one after the other, and then emits a complete notification.
Expand All @@ -36,8 +36,8 @@ export class ArrayObservable<T> extends Observable<T> {
* This static operator is useful for creating a simple Observable that only
* emits the arguments given, and the complete notification thereafter. It can
* be used for composing with other Observables, such as with {@link concat}.
* By default, it uses a `null` Scheduler, which means the `next`
* notifications are sent synchronously, although with a different Scheduler
* By default, it uses a `null` IScheduler, which means the `next`
* notifications are sent synchronously, although with a different IScheduler
* it is possible to determine when those notifications will be delivered.
*
* @example <caption>Emit 10, 20, 30, then 'a', 'b', 'c', then start ticking every second.</caption>
Expand All @@ -53,15 +53,15 @@ export class ArrayObservable<T> extends Observable<T> {
* @see {@link throw}
*
* @param {...T} values Arguments that represent `next` values to be emitted.
* @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling
* @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
* the emissions of the `next` notifications.
* @return {Observable<T>} An Observable that emits each given input value.
* @static true
* @name of
* @owner Observable
*/
static of<T>(...array: Array<T | Scheduler>): Observable<T> {
let scheduler = <Scheduler>array[array.length - 1];
static of<T>(...array: Array<T | IScheduler>): Observable<T> {
let scheduler = <IScheduler>array[array.length - 1];
if (isScheduler(scheduler)) {
array.pop();
} else {
Expand Down Expand Up @@ -101,7 +101,7 @@ export class ArrayObservable<T> extends Observable<T> {
// value used if Array has one value and _isScalar
value: any;

constructor(private array: T[], private scheduler?: Scheduler) {
constructor(private array: T[], private scheduler?: IScheduler) {
super();
if (!scheduler && array.length === 1) {
this._isScalar = true;
Expand Down
38 changes: 19 additions & 19 deletions src/observable/BoundCallbackObservable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { Subscription } from '../Subscription';
import { Scheduler } from '../Scheduler';
import { IScheduler } from '../Scheduler';
import { tryCatch } from '../util/tryCatch';
import { errorObject } from '../util/errorObject';
import { AsyncSubject } from '../AsyncSubject';
Expand All @@ -15,22 +15,22 @@ export class BoundCallbackObservable<T> extends Observable<T> {
subject: AsyncSubject<T>;

/* tslint:disable:max-line-length */
static create<R>(callbackFunc: (callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<R>(callbackFunc: (callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<T>(callbackFunc: Function, selector?: void, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
static create<T>(callbackFunc: Function, selector?: (...args: any[]) => T, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
static create<R>(callbackFunc: (callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<R>(callbackFunc: (callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (...args: any[]) => any) => any, selector: (...args: any[]) => R, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<T>(callbackFunc: Function, selector?: void, scheduler?: IScheduler): (...args: any[]) => Observable<T>;
static create<T>(callbackFunc: Function, selector?: (...args: any[]) => T, scheduler?: IScheduler): (...args: any[]) => Observable<T>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ export class BoundCallbackObservable<T> extends Observable<T> {
*/
static create<T>(func: Function,
selector: Function | void = undefined,
scheduler?: Scheduler): (...args: any[]) => Observable<T> {
scheduler?: IScheduler): (...args: any[]) => Observable<T> {
return (...args: any[]): Observable<T> => {
return new BoundCallbackObservable<T>(func, <any>selector, args, scheduler);
};
Expand All @@ -80,7 +80,7 @@ export class BoundCallbackObservable<T> extends Observable<T> {
constructor(private callbackFunc: Function,
private selector: Function,
private args: any[],
private scheduler: Scheduler) {
private scheduler: IScheduler) {
super();
}

Expand Down
24 changes: 12 additions & 12 deletions src/observable/BoundNodeCallbackObservable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { Subscription } from '../Subscription';
import { Scheduler } from '../Scheduler';
import { IScheduler } from '../Scheduler';
import { Action } from '../scheduler/Action';
import { tryCatch } from '../util/tryCatch';
import { errorObject } from '../util/errorObject';
Expand All @@ -16,15 +16,15 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
subject: AsyncSubject<T>;

/* tslint:disable:max-line-length */
static create<R>(callbackFunc: (callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: Scheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<T>(callbackFunc: Function, selector?: void, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
static create<T>(callbackFunc: Function, selector?: (...args: any[]) => T, scheduler?: Scheduler): (...args: any[]) => Observable<T>;
static create<R>(callbackFunc: (callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): () => Observable<R>;
static create<T, R>(callbackFunc: (v1: T, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T) => Observable<R>;
static create<T, T2, R>(callbackFunc: (v1: T, v2: T2, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2) => Observable<R>;
static create<T, T2, T3, R>(callbackFunc: (v1: T, v2: T2, v3: T3, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3) => Observable<R>;
static create<T, T2, T3, T4, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4) => Observable<R>;
static create<T, T2, T3, T4, T5, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => Observable<R>;
static create<T, T2, T3, T4, T5, T6, R>(callbackFunc: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6, callback: (err: any, result: R) => any) => any, selector?: void, scheduler?: IScheduler): (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => Observable<R>;
static create<T>(callbackFunc: Function, selector?: void, scheduler?: IScheduler): (...args: any[]) => Observable<T>;
static create<T>(callbackFunc: Function, selector?: (...args: any[]) => T, scheduler?: IScheduler): (...args: any[]) => Observable<T>;
/* tslint:enable:max-line-length */

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
*/
static create<T>(func: Function,
selector: Function | void = undefined,
scheduler?: Scheduler): (...args: any[]) => Observable<T> {
scheduler?: IScheduler): (...args: any[]) => Observable<T> {
return (...args: any[]): Observable<T> => {
return new BoundNodeCallbackObservable<T>(func, <any>selector, args, scheduler);
};
Expand All @@ -77,7 +77,7 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
constructor(private callbackFunc: Function,
private selector: Function,
private args: any[],
public scheduler: Scheduler) {
public scheduler: IScheduler) {
super();
}

Expand Down
8 changes: 4 additions & 4 deletions src/observable/EmptyObservable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scheduler } from '../Scheduler';
import { IScheduler } from '../Scheduler';
import { Subscriber } from '../Subscriber';
import { Observable } from '../Observable';
import { TeardownLogic } from '../Subscription';
Expand Down Expand Up @@ -49,15 +49,15 @@ export class EmptyObservable<T> extends Observable<T> {
* @see {@link of}
* @see {@link throw}
*
* @param {Scheduler} [scheduler] A {@link Scheduler} to use for scheduling
* @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
* the emission of the complete notification.
* @return {Observable} An "empty" Observable: emits only the complete
* notification.
* @static true
* @name empty
* @owner Observable
*/
static create<T>(scheduler?: Scheduler): Observable<T> {
static create<T>(scheduler?: IScheduler): Observable<T> {
return new EmptyObservable<T>(scheduler);
}

Expand All @@ -66,7 +66,7 @@ export class EmptyObservable<T> extends Observable<T> {
subscriber.complete();
}

constructor(private scheduler?: Scheduler) {
constructor(private scheduler?: IScheduler) {
super();
}

Expand Down
Loading

0 comments on commit a0d28a8

Please sign in to comment.