Skip to content

Instantly share code, notes, and snippets.

@psyrendust
Created November 4, 2015 00:54
Show Gist options
  • Save psyrendust/85bdc4c3c89fae120466 to your computer and use it in GitHub Desktop.
Save psyrendust/85bdc4c3c89fae120466 to your computer and use it in GitHub Desktop.
Browserify + Babelify Issue
/**
* 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