Created
November 4, 2015 00:54
-
-
Save psyrendust/85bdc4c3c89fae120466 to your computer and use it in GitHub Desktop.
Browserify + Babelify Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a queue that persists after calling `apply()`. | |
*/ | |
export class PersistentQueue { | |
_queue = []; | |
_size = 0; | |
constructor() {} | |
onUpdate(callback) { | |
this._queue.push(callback); | |
this._size++; | |
return this; | |
} | |
apply() { | |
for (let i = 0; i < this._size; i++) { | |
this._queue[i](...arguments); | |
} | |
return this; | |
} | |
getSize() { | |
return this._size; | |
} | |
} | |
/** | |
* Creates a queue that empties after calling `apply()`. | |
*/ | |
export class TempQueue extends PersistentQueue { | |
apply() { | |
while (this._queue.length) { | |
this._queue.shift()(...arguments); | |
this._size--; | |
} | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment