regexper-static/src/js/parser/javascript/parser_state.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-04-16 21:52:50 +00:00
// State tracking for an in-progress parse and render.
export default class ParserState {
2015-04-16 21:52:50 +00:00
// - __progress__ - DOM node to update to indicate completion progress.
constructor(progress) {
2015-04-16 21:52:50 +00:00
// Tracks the number of capture groups in the expression.
this.groupCounter = 1;
2015-04-16 21:52:50 +00:00
// Cancels the in-progress render when set to true.
this.cancelRender = false;
2015-04-16 21:52:50 +00:00
// Warnings that have been generated while rendering.
this.warnings = [];
2015-04-16 21:52:50 +00:00
// Used to display the progress indicator
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.
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) + '%';
}
}
}