Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert SchedulerLike interface changes #5268

Merged
merged 2 commits into from Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/Scheduler-spec.ts
Expand Up @@ -23,8 +23,8 @@ describe('Scheduler.queue', () => {
let call2 = false;
(queue as QueueScheduler).active = false;
queue.schedule(function (state) {
call1 = state.call1;
call2 = state.call2;
call1 = state!.call1;
call2 = state!.call2;
if (!call2) {
this.schedule({ call1: true, call2: true });
}
Expand Down
4 changes: 2 additions & 2 deletions spec/schedulers/AsapScheduler-spec.ts
Expand Up @@ -54,7 +54,7 @@ describe('Scheduler.asap', () => {
this.schedule(state, state.period);
}
}
asap.schedule(dispatch, period, state);
asap.schedule(dispatch as any, period, state);
expect(state).to.have.property('index', 0);
expect(stubSetInterval).to.have.property('callCount', 1);
fakeTimer.tick(period);
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Scheduler.asap', () => {
this.schedule(state, state.period);
}
}
asap.schedule(dispatch, period, state);
asap.schedule(dispatch as any, period, state);
expect(state).to.have.property('index', 0);
expect(stubSetInterval).to.have.property('callCount', 1);
fakeTimer.tick(period);
Expand Down
2 changes: 1 addition & 1 deletion spec/schedulers/QueueScheduler-spec.ts
Expand Up @@ -29,7 +29,7 @@ describe('Scheduler.queue', () => {
let state: Array<number> = [];

queue.schedule(function (index) {
state.push(index);
state.push(index!);
if (index === 0) {
this.schedule(1, 100);
} else if (index === 1) {
Expand Down
14 changes: 7 additions & 7 deletions spec/schedulers/VirtualTimeScheduler-spec.ts
Expand Up @@ -11,7 +11,7 @@ describe('VirtualTimeScheduler', () => {
it('should schedule things in order when flushed if each this is scheduled synchrously', () => {
const v = new VirtualTimeScheduler();
const invoked: number[] = [];
const invoke = (state: number) => {
const invoke: any = (state: number) => {
invoked.push(state);
};
v.schedule(invoke, 0, 1);
Expand All @@ -28,7 +28,7 @@ describe('VirtualTimeScheduler', () => {
it('should schedule things in order when flushed if each this is scheduled at random', () => {
const v = new VirtualTimeScheduler();
const invoked: number[] = [];
const invoke = (state: number) => {
const invoke: any = (state: number) => {
invoked.push(state);
};
v.schedule(invoke, 0, 1);
Expand All @@ -46,7 +46,7 @@ describe('VirtualTimeScheduler', () => {
it('should schedule things in order when there are negative delays', () => {
const v = new VirtualTimeScheduler();
const invoked: number[] = [];
const invoke = (state: number) => {
const invoke: any = (state: number) => {
invoked.push(state);
};
v.schedule(invoke, 0, 1);
Expand All @@ -66,7 +66,7 @@ describe('VirtualTimeScheduler', () => {
let count = 0;
const expected = [100, 200, 300];

v.schedule<string>(function (this: SchedulerAction<string>, state: string) {
v.schedule<string>(function (this: SchedulerAction<string>, state?: string) {
if (++count === 3) {
return;
}
Expand All @@ -84,7 +84,7 @@ describe('VirtualTimeScheduler', () => {
const messages: string[] = [];

const action: VirtualAction<string> = <VirtualAction<string>> v.schedule(
state => messages.push(state),
state => messages.push(state!),
10,
'first message'
);
Expand All @@ -104,7 +104,7 @@ describe('VirtualTimeScheduler', () => {

messages.forEach((message, index) => {
v.schedule(
(state: string) => actualMessages.push(state),
state => actualMessages.push(state!),
index * MAX_FRAMES,
message
);
Expand All @@ -125,7 +125,7 @@ describe('VirtualTimeScheduler', () => {

messages.forEach((message, index) => {
v.schedule(
state => actualMessages.push(state),
state => actualMessages.push(state!),
index * MAX_FRAMES,
message
);
Expand Down
4 changes: 2 additions & 2 deletions src/internal/Scheduler.ts
Expand Up @@ -62,7 +62,7 @@ export class Scheduler implements SchedulerLike {
* @return {Subscription} A subscription in order to be able to unsubscribe
* the scheduled work.
*/
public schedule<T = undefined>(work: (this: SchedulerAction<T>, state: T) => void, delay: number = 0, state?: T): Subscription {
return new this.SchedulerAction<T>(this, work).schedule(state!, delay);
public schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number = 0, state?: T): Subscription {
return new this.SchedulerAction<T>(this, work).schedule(state, delay);
}
}
2 changes: 1 addition & 1 deletion src/internal/observable/SubscribeOnObservable.ts
Expand Up @@ -45,7 +45,7 @@ export class SubscribeOnObservable<T> extends Observable<T> {
const source = this.source;
const scheduler = this.scheduler;

return scheduler.schedule<DispatchArg<any>>(SubscribeOnObservable.dispatch, delay, {
return scheduler.schedule<DispatchArg<any>>(SubscribeOnObservable.dispatch as any, delay, {
source, subscriber
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/observable/bindCallback.ts
Expand Up @@ -224,7 +224,7 @@ export function bindCallback<T>(
const state: DispatchState<T> = {
args, subscriber, params,
};
return scheduler.schedule<DispatchState<T>>(dispatch, 0, state);
return scheduler.schedule<DispatchState<T>>(dispatch as any, 0, state);
}
});
};
Expand Down Expand Up @@ -253,7 +253,7 @@ function dispatch<T>(this: SchedulerAction<DispatchState<T>>, state: DispatchSta

const handler = (...innerArgs: any[]) => {
const value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
this.add(scheduler.schedule<NextState<T>>(dispatchNext, 0, { value, subject: subject! }));
this.add(scheduler.schedule<NextState<T>>(dispatchNext as any, 0, { value, subject: subject! }));
};

try {
Expand Down
8 changes: 4 additions & 4 deletions src/internal/observable/bindNodeCallback.ts
Expand Up @@ -208,7 +208,7 @@ export function bindNodeCallback<T>(
}
return subject.subscribe(subscriber);
} else {
return scheduler.schedule<DispatchState<T>>(dispatch, 0, { params, subscriber, context });
return scheduler.schedule<DispatchState<T>>(dispatch as any, 0, { params, subscriber, context });
}
});
};
Expand Down Expand Up @@ -239,17 +239,17 @@ function dispatch<T>(this: SchedulerAction<DispatchState<T>>, state: DispatchSta
const handler = (...innerArgs: any[]) => {
const err = innerArgs.shift();
if (err) {
this.add(scheduler.schedule<DispatchErrorArg<T>>(dispatchError, 0, { err, subject }));
this.add(scheduler.schedule<DispatchErrorArg<T>>(dispatchError as any, 0, { err, subject }));
} else {
const value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
this.add(scheduler.schedule<DispatchNextArg<T>>(dispatchNext, 0, { value, subject }));
this.add(scheduler.schedule<DispatchNextArg<T>>(dispatchNext as any, 0, { value, subject }));
}
};

try {
callbackFunc.apply(context, [...args, handler]);
} catch (err) {
this.add(scheduler.schedule<DispatchErrorArg<T>>(dispatchError, 0, { err, subject }));
this.add(scheduler.schedule<DispatchErrorArg<T>>(dispatchError as any, 0, { err, subject }));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/observable/generate.ts
Expand Up @@ -361,7 +361,7 @@ export function generate<T, S>(initialStateOrOptions: S | GenerateOptions<T, S>,
return new Observable<T>(subscriber => {
let state = initialState;
if (scheduler) {
return scheduler.schedule<SchedulerState<T, S>>(dispatch, 0, {
return scheduler.schedule<SchedulerState<T, S>>(dispatch as any, 0, {
subscriber,
iterate: iterate!,
condition,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/observable/interval.ts
Expand Up @@ -64,7 +64,7 @@ export function interval(period = 0,

return new Observable<number>(subscriber => {
subscriber.add(
scheduler.schedule(dispatch, period, { subscriber, counter: 0, period })
scheduler.schedule(dispatch as any, period, { subscriber, counter: 0, period })
);
return subscriber;
});
Expand Down
7 changes: 5 additions & 2 deletions src/internal/observable/pairs.ts
Expand Up @@ -67,8 +67,11 @@ export function pairs<T>(obj: Object, scheduler?: SchedulerLike): Observable<[st
const keys = Object.keys(obj);
const subscription = new Subscription();
subscription.add(
scheduler.schedule<{ keys: string[], index: number, subscriber: Subscriber<[string, T]>, subscription: Subscription, obj: Object }>
(dispatch, 0, { keys, index: 0, subscriber, subscription, obj }));
scheduler.schedule<{ keys: string[], index: number, subscriber: Subscriber<[string, T]>, subscription: Subscription, obj: Object }>(
dispatch as any,
0,
{ keys, index: 0, subscriber, subscription, obj }
));
return subscription;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/observable/throwError.ts
Expand Up @@ -70,7 +70,7 @@ export function throwError(error: any, scheduler?: SchedulerLike): Observable<ne
if (!scheduler) {
return new Observable(subscriber => subscriber.error(error));
} else {
return new Observable(subscriber => scheduler.schedule(dispatch, 0, { error, subscriber }));
return new Observable(subscriber => scheduler.schedule(dispatch as any, 0, { error, subscriber }));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/observable/timer.ts
Expand Up @@ -74,7 +74,7 @@ export function timer(dueTime: number | Date = 0,
? (dueTime as number)
: (+dueTime - scheduler!.now());

return scheduler!.schedule(dispatch, due, {
return scheduler!.schedule(dispatch as any, due, {
index: 0, period, subscriber
});
});
Expand Down
10 changes: 7 additions & 3 deletions src/internal/operators/bufferTime.ts
Expand Up @@ -147,8 +147,8 @@ class BufferTimeSubscriber<T> extends Subscriber<T> {
} else {
const closeState = { subscriber: this, context };
const creationState: DispatchCreateArg<T> = { bufferTimeSpan, bufferCreationInterval, subscriber: this, scheduler };
this.add(context.closeAction = scheduler.schedule<DispatchCloseArg<T>>(dispatchBufferClose, bufferTimeSpan, closeState));
this.add(scheduler.schedule<DispatchCreateArg<T>>(dispatchBufferCreation, bufferCreationInterval!, creationState));
this.add(context.closeAction = scheduler.schedule<DispatchCloseArg<T>>(dispatchBufferClose as any, bufferTimeSpan, closeState));
this.add(scheduler.schedule<DispatchCreateArg<T>>(dispatchBufferCreation as any, bufferCreationInterval!, creationState));
}
}

Expand Down Expand Up @@ -239,7 +239,11 @@ function dispatchBufferCreation<T>(this: SchedulerAction<DispatchCreateArg<T>>,
const context = subscriber.openContext();
const action = <SchedulerAction<DispatchCreateArg<T>>>this;
if (!subscriber.closed) {
subscriber.add(context.closeAction = scheduler.schedule<DispatchCloseArg<T>>(dispatchBufferClose, bufferTimeSpan, { subscriber, context }));
subscriber.add(context.closeAction = scheduler.schedule<DispatchCloseArg<T>>(
dispatchBufferClose as any,
bufferTimeSpan,
{ subscriber, context }
));
action.schedule(state, bufferCreationInterval!);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/debounceTime.ts
Expand Up @@ -97,7 +97,7 @@ class DebounceTimeSubscriber<T> extends Subscriber<T> {
this.clearDebounce();
this.lastValue = value;
this.hasValue = true;
this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));
this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext as any, this.dueTime, this));
}

protected _complete() {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/delay.ts
Expand Up @@ -118,7 +118,7 @@ class DelaySubscriber<T> extends Subscriber<T> {
private _schedule(scheduler: SchedulerLike): void {
this.active = true;
const destination = this.destination as Subscription;
destination.add(scheduler.schedule<DelayState<T>>(DelaySubscriber.dispatch, this.delay, {
destination.add(scheduler.schedule<DelayState<T>>(DelaySubscriber.dispatch as any, this.delay, {
source: this, destination: this.destination, scheduler: scheduler
}));
}
Expand Down
6 changes: 5 additions & 1 deletion src/internal/operators/expand.ts
Expand Up @@ -135,7 +135,11 @@ export class ExpandSubscriber<T, R> extends OuterSubscriber<T, R> {
} else {
const state: DispatchArg<T, R> = { subscriber: this, result, value, index };
const destination = this.destination as Subscription;
destination.add(this.scheduler.schedule<DispatchArg<T, R>>(ExpandSubscriber.dispatch, 0, state));
destination.add(this.scheduler.schedule<DispatchArg<T, R>>(
ExpandSubscriber.dispatch as any,
0,
state
));
}
} catch (e) {
destination.error(e);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/observeOn.ts
Expand Up @@ -95,7 +95,7 @@ export class ObserveOnSubscriber<T> extends Subscriber<T> {
private scheduleMessage(notification: Notification<any>): void {
const destination = this.destination as Subscription;
destination.add(this.scheduler.schedule(
ObserveOnSubscriber.dispatch,
ObserveOnSubscriber.dispatch as any,
this.delay,
new ObserveOnMessage(notification, this.destination)
));
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/throttleTime.ts
Expand Up @@ -130,7 +130,7 @@ class ThrottleTimeSubscriber<T> extends Subscriber<T> {
this._hasTrailingValue = true;
}
} else {
this.add(this.throttled = this.scheduler.schedule<DispatchArg<T>>(dispatchNext, this.duration, { subscriber: this }));
this.add(this.throttled = this.scheduler.schedule<DispatchArg<T>>(dispatchNext as any, this.duration, { subscriber: this }));
if (this.leading) {
this.destination.next(value);
} else if (this.trailing) {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/timeoutWith.ts
Expand Up @@ -123,7 +123,7 @@ class TimeoutWithSubscriber<T, R> extends OuterSubscriber<T, R> {
this.action = (<SchedulerAction<TimeoutWithSubscriber<T, R>>> action.schedule(this, this.waitFor));
} else {
this.add(this.action = (<SchedulerAction<TimeoutWithSubscriber<T, R>>> this.scheduler.schedule<TimeoutWithSubscriber<T, R>>(
TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this
TimeoutWithSubscriber.dispatchTimeout as any, this.waitFor, this
)));
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/internal/operators/windowTime.ts
Expand Up @@ -192,13 +192,13 @@ class WindowTimeSubscriber<T> extends Subscriber<T> {

const window = this.openWindow();
if (windowCreationInterval !== null && windowCreationInterval >= 0) {
const closeState: CloseState<T> = { subscriber: this, window, context: <any>null };
const closeState: CloseState<T> = { subscriber: this, window, context: null! };
const creationState: CreationState<T> = { windowTimeSpan, windowCreationInterval, subscriber: this, scheduler };
this.add(scheduler.schedule<CloseState<T>>(dispatchWindowClose, windowTimeSpan, closeState));
this.add(scheduler.schedule<CreationState<T>>(dispatchWindowCreation, windowCreationInterval, creationState));
this.add(scheduler.schedule<CloseState<T>>(dispatchWindowClose as any, windowTimeSpan, closeState));
this.add(scheduler.schedule<CreationState<T>>(dispatchWindowCreation as any, windowCreationInterval, creationState));
} else {
const timeSpanOnlyState: TimeSpanOnlyState<T> = { subscriber: this, window, windowTimeSpan };
this.add(scheduler.schedule<TimeSpanOnlyState<T>>(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState));
this.add(scheduler.schedule<TimeSpanOnlyState<T>>(dispatchWindowTimeSpanOnly as any, windowTimeSpan, timeSpanOnlyState));
}
}

Expand Down Expand Up @@ -268,9 +268,9 @@ function dispatchWindowCreation<T>(this: SchedulerAction<CreationState<T>>, stat
const { windowTimeSpan, subscriber, scheduler, windowCreationInterval } = state;
const window = subscriber.openWindow();
const action = this;
let context: CloseWindowContext<T> = { action, subscription: <any>null };
let context: CloseWindowContext<T> = { action, subscription: null! };
const timeSpanState: CloseState<T> = { subscriber, window, context };
context.subscription = scheduler.schedule<CloseState<T>>(dispatchWindowClose, windowTimeSpan, timeSpanState);
context.subscription = scheduler.schedule<CloseState<T>>(dispatchWindowClose as any, windowTimeSpan, timeSpanState);
action.add(context.subscription);
action.schedule(state, windowCreationInterval);
}
Expand Down
8 changes: 4 additions & 4 deletions src/internal/scheduler/Action.ts
Expand Up @@ -9,15 +9,15 @@ import { SchedulerAction } from '../types';
*
* ```ts
* class Action<T> extends Subscription {
* new (scheduler: Scheduler, work: (state: T) => void);
* schedule(state: T, delay: number = 0): Subscription;
* new (scheduler: Scheduler, work: (state?: T) => void);
* schedule(state?: T, delay: number = 0): Subscription;
* }
* ```
*
* @class Action<T>
*/
export class Action<T> extends Subscription {
constructor(scheduler: Scheduler, work: (this: SchedulerAction<T>, state: T) => void) {
constructor(scheduler: Scheduler, work: (this: SchedulerAction<T>, state?: T) => void) {
super();
}
/**
Expand All @@ -30,7 +30,7 @@ export class Action<T> extends Subscription {
* time unit is implicit and defined by the Scheduler.
* @return {void}
*/
public schedule(state: T, delay: number = 0): Subscription {
public schedule(state?: T, delay: number = 0): Subscription {
return this;
}
}
2 changes: 1 addition & 1 deletion src/internal/scheduler/AnimationFrameAction.ts
Expand Up @@ -10,7 +10,7 @@ import { SchedulerAction } from '../types';
export class AnimationFrameAction<T> extends AsyncAction<T> {

constructor(protected scheduler: AnimationFrameScheduler,
protected work: (this: SchedulerAction<T>, state: T) => void) {
protected work: (this: SchedulerAction<T>, state?: T) => void) {
super(scheduler, work);
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/scheduler/AsapAction.ts
Expand Up @@ -10,7 +10,7 @@ import { SchedulerAction } from '../types';
export class AsapAction<T> extends AsyncAction<T> {

constructor(protected scheduler: AsapScheduler,
protected work: (this: SchedulerAction<T>, state: T) => void) {
protected work: (this: SchedulerAction<T>, state?: T) => void) {
super(scheduler, work);
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/scheduler/AsyncAction.ts
Expand Up @@ -17,7 +17,7 @@ export class AsyncAction<T> extends Action<T> {
protected pending: boolean = false;

constructor(protected scheduler: AsyncScheduler,
protected work: (this: SchedulerAction<T>, state: T) => void) {
protected work: (this: SchedulerAction<T>, state?: T) => void) {
super(scheduler, work);
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/scheduler/AsyncScheduler.ts
Expand Up @@ -34,7 +34,7 @@ export class AsyncScheduler extends Scheduler {
});
}

public schedule<T = undefined>(work: (this: SchedulerAction<T>, state: T) => void, delay: number = 0, state?: T): Subscription {
public schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number = 0, state?: T): Subscription {
if (AsyncScheduler.delegate && AsyncScheduler.delegate !== this) {
return AsyncScheduler.delegate.schedule(work, delay, state);
} else {
Expand Down