2015-04-16 21:52:50 +00:00
|
|
|
// State tracking for an in-progress parse and render.
|
2015-03-14 18:01:25 +00:00
|
|
|
export default class ParserState {
|
2015-04-16 21:52:50 +00:00
|
|
|
// - __progress__ - DOM node to update to indicate completion progress.
|
2015-03-14 18:01:25 +00:00
|
|
|
constructor(progress) {
|
2015-04-16 21:52:50 +00:00
|
|
|
// Tracks the number of capture groups in the expression.
|
2015-03-14 18:01:25 +00:00
|
|
|
this.groupCounter = 1;
|
2015-04-16 21:52:50 +00:00
|
|
|
// Cancels the in-progress render when set to true.
|
2015-03-14 18:01:25 +00:00
|
|
|
this.cancelRender = false;
|
2015-04-16 21:52:50 +00:00
|
|
|
// Warnings that have been generated while rendering.
|
2015-03-14 18:01:25 +00:00
|
|
|
this.warnings = [];
|
2015-04-16 21:52:50 +00:00
|
|
|
|
|
|
|
// Used to display the progress indicator
|
2015-03-14 18:01:25 +00:00
|
|
|
this._renderCounter = 0;
|
|
|
|
this._maxCounter = 0;
|
|
|
|
this._progress = progress;
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:52:50 +00:00
|
|
|
// Counts the number of in-progress rendering steps. As the counter goes up,
|
|
|
|
// a maximum value is also tracked. The maximum value and current render
|
|
|
|
// counter are used to calculate the completion process.
|
2015-03-14 18:01:25 +00:00
|
|
|
get renderCounter() {
|
|
|
|
return this._renderCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
set renderCounter(value) {
|
|
|
|
if (value > this.renderCounter) {
|
|
|
|
this._maxCounter = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._renderCounter = value;
|
|
|
|
|
|
|
|
if (this._maxCounter && !this.cancelRender) {
|
|
|
|
this._progress.style.width = ((1 - this.renderCounter / this._maxCounter) * 100).toFixed(2) + '%';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|