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

refactor(Scheduler): clearify the signature which Scheduler.schedule() takes as work. #2078

Merged
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
3 changes: 2 additions & 1 deletion spec/schedulers/VirtualTimeScheduler-spec.ts
@@ -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
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
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
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
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
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
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
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