Code coverage report for src/scheduler/QueueAction.ts

Statements: 93.55% (29 / 31)      Branches: 66.67% (4 / 6)      Functions: 100% (5 / 5)      Lines: 92.86% (26 / 28)      Ignored: none     

All files » src/scheduler/ » QueueAction.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 491       1       149 149 149     1 456       456 456 456 456 456     1 489     489     1   137 137 137   137 137 137   137 2     137   1
import {Subscription} from '../Subscription';
import {Scheduler} from '../Scheduler';
import {Action} from './Action';
 
export class QueueAction<T> extends Subscription<T> implements Action {
 
  state: any;
 
  constructor(public scheduler: Scheduler,
              public work: (x?: any) => Subscription<T> | void) {
    super();
  }
 
  schedule(state?: any): Action {
    Iif (this.isUnsubscribed) {
      return this;
    }
 
    this.state = state;
    const scheduler = this.scheduler;
    scheduler.actions.push(this);
    scheduler.flush();
    return this;
  }
 
  execute() {
    Iif (this.isUnsubscribed) {
      throw new Error('How did did we execute a canceled Action?');
    }
    this.work(this.state);
  }
 
  unsubscribe() {
 
    const scheduler = this.scheduler;
    const actions = scheduler.actions;
    const index = actions.indexOf(this);
 
    this.work = void 0;
    this.state = void 0;
    this.scheduler = void 0;
 
    if (index !== -1) {
      actions.splice(index, 1);
    }
 
    super.unsubscribe();
  }
}