1
+ import searchTimer from './backburner/binary-search' ;
2
+ import DeferredActionQueues from './backburner/deferred-action-queues' ;
3
+ import Evented from './backburner/evented' ;
4
+ import iteratorDrain , { Iteratable } from './backburner/iterator-drain' ;
5
+ import Queue , { QUEUE_STATE } from './backburner/queue' ;
1
6
import {
2
7
findItem ,
3
8
findTimer ,
4
9
getOnError ,
5
10
isCoercableNumber
6
11
} from './backburner/utils' ;
7
12
8
- import searchTimer from './backburner/binary-search' ;
9
- import DeferredActionQueues from './backburner/deferred-action-queues' ;
10
- import iteratorDrain , { Iteratable } from './backburner/iterator-drain' ;
11
-
12
- import Queue , { QUEUE_STATE } from './backburner/queue' ;
13
-
14
13
type Timer = any ;
15
14
16
15
const noop = function ( ) { } ;
@@ -45,7 +44,7 @@ function parseArgs() {
45
44
46
45
let UUID = 0 ;
47
46
48
- export default class Backburner {
47
+ export default class Backburner extends Evented {
49
48
public static Queue = Queue ;
50
49
51
50
public DEBUG = false ;
@@ -60,13 +59,6 @@ export default class Backburner {
60
59
private instanceStack : DeferredActionQueues [ ] = [ ] ;
61
60
private _debouncees : any [ ] = [ ] ;
62
61
private _throttlers : any [ ] = [ ] ;
63
- private _eventCallbacks : {
64
- end : Function [ ] ;
65
- begin : Function [ ] ;
66
- } = {
67
- end : [ ] ,
68
- begin : [ ]
69
- } ;
70
62
71
63
private _timerTimeoutId : number | null = null ;
72
64
private _timers : any [ ] = [ ] ;
@@ -83,7 +75,8 @@ export default class Backburner {
83
75
private _autorun : number | null = null ;
84
76
private _boundAutorunEnd : ( ) => void ;
85
77
86
- constructor ( queueNames : string [ ] , options : any = { } ) {
78
+ constructor ( queueNames : string [ ] , options : any = { } ) {
79
+ super ( ) ;
87
80
this . queueNames = queueNames ;
88
81
this . options = options ;
89
82
if ( ! this . options . defaultQueue ) {
@@ -172,38 +165,6 @@ export default class Backburner {
172
165
}
173
166
}
174
167
175
- public on ( eventName , callback ) {
176
- if ( typeof callback !== 'function' ) {
177
- throw new TypeError ( `Callback must be a function` ) ;
178
- }
179
- let callbacks = this . _eventCallbacks [ eventName ] ;
180
- if ( callbacks !== undefined ) {
181
- callbacks . push ( callback ) ;
182
- } else {
183
- throw new TypeError ( `Cannot on() event ${ eventName } because it does not exist` ) ;
184
- }
185
- }
186
-
187
- public off ( eventName , callback ) {
188
- let callbacks = this . _eventCallbacks [ eventName ] ;
189
- if ( ! eventName || callbacks === undefined ) {
190
- throw new TypeError ( `Cannot off() event ${ eventName } because it does not exist` ) ;
191
- }
192
- let callbackFound = false ;
193
- if ( callback ) {
194
- for ( let i = 0 ; i < callbacks . length ; i ++ ) {
195
- if ( callbacks [ i ] === callback ) {
196
- callbackFound = true ;
197
- callbacks . splice ( i , 1 ) ;
198
- i -- ;
199
- }
200
- }
201
- }
202
- if ( ! callbackFound ) {
203
- throw new TypeError ( `Cannot off() callback that does not exist` ) ;
204
- }
205
- }
206
-
207
168
public run ( target : Function ) ;
208
169
public run ( target : Function | any | null , method ?: Function | string , ...args ) ;
209
170
public run ( target : any | null | undefined , method ?: Function , ...args : any [ ] ) ;
@@ -614,27 +575,6 @@ export default class Backburner {
614
575
return false ;
615
576
}
616
577
617
- /**
618
- Trigger an event. Supports up to two arguments. Designed around
619
- triggering transition events from one run loop instance to the
620
- next, which requires an argument for the first instance and then
621
- an argument for the next instance.
622
-
623
- @private
624
- @method _trigger
625
- @param {String } eventName
626
- @param {any } arg1
627
- @param {any } arg2
628
- */
629
- private _trigger < T , U > ( eventName : string , arg1 : T , arg2 : U ) {
630
- let callbacks = this . _eventCallbacks [ eventName ] ;
631
- if ( callbacks !== undefined ) {
632
- for ( let i = 0 ; i < callbacks . length ; i ++ ) {
633
- callbacks [ i ] ( arg1 , arg2 ) ;
634
- }
635
- }
636
- }
637
-
638
578
private _runExpiredTimers ( ) {
639
579
this . _timerTimeoutId = null ;
640
580
if ( this . _timers . length > 0 ) {
0 commit comments