Skip to content

Commit

Permalink
refactor(Scheduler): clearify the signature which `Scheduler.schedule…
Browse files Browse the repository at this point in the history
…()` takes as `work`. (#2078)

I think this would not be a breaking change by these reasons:

- There are no problem if we pass the function which does not has `this` specifying.
- There are no problem if we pass the function which has `this: any` or `this: Action<T>`.
  - This case is valid with the actual behavior.
- If we pass the function which has `this: SomeNonValidTypeWithAction<T>`,
  then, basically, its code would be wrong.
  • Loading branch information
tetsuharuohzeki authored and benlesh committed Nov 4, 2016
1 parent f5669fd commit 9ec444e
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion spec/schedulers/VirtualTimeScheduler-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import { VirtualAction } from '../../dist/cjs/scheduler/VirtualTimeScheduler';

const VirtualTimeScheduler = Rx.VirtualTimeScheduler;

Expand Down Expand Up @@ -68,7 +69,7 @@ describe('VirtualTimeScheduler', () => {
let count = 0;
const expected = [100, 200, 300];

v.schedule(function(state) {
v.schedule<string>(function(this: VirtualAction<string>, state: string) {
if (++count === 3) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Scheduler {
* @return {Subscription} A subscription in order to be able to unsubscribe
* the scheduled work.
*/
public schedule<T>(work: (state?: T) => void, delay: number = 0, state?: T): Subscription {
public schedule<T>(work: (this: Action<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/scheduler/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Subscription } from '../Subscription';
* @class Action<T>
*/
export class Action<T> extends Subscription {
constructor(scheduler: Scheduler, work: (state?: T) => void) {
constructor(scheduler: Scheduler, work: (this: Action<T>, state?: T) => void) {
super();
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/AnimationFrameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AnimationFrameScheduler } from './AnimationFrameScheduler';
export class AnimationFrameAction<T> extends AsyncAction<T> {

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

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/AsapAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AsapScheduler } from './AsapScheduler';
export class AsapAction<T> extends AsyncAction<T> {

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

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/AsyncAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AsyncAction<T> extends Action<T> {
protected pending: boolean = false;

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

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/QueueAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { QueueScheduler } from './QueueScheduler';
export class QueueAction<T> extends AsyncAction<T> {

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

Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/VirtualTimeScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class VirtualTimeScheduler extends AsyncScheduler {
export class VirtualAction<T> extends AsyncAction<T> {

constructor(protected scheduler: VirtualTimeScheduler,
protected work: (state?: T) => void,
protected work: (this: VirtualAction<T>, state?: T) => void,
protected index: number = scheduler.index += 1) {
super(scheduler, work);
this.index = scheduler.index = index;
Expand Down

0 comments on commit 9ec444e

Please sign in to comment.