mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
sequencer logic for variable import
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
function ImportSequencer(onSequencerEmpty) {
|
||||
this.imports = [];
|
||||
this.variableImports = [];
|
||||
this._onSequencerEmpty = onSequencerEmpty;
|
||||
}
|
||||
|
||||
@@ -18,14 +19,26 @@ ImportSequencer.prototype.addImport = function(callback) {
|
||||
};
|
||||
};
|
||||
|
||||
ImportSequencer.prototype.addVariableImport = function(callback) {
|
||||
this.variableImports.push(callback);
|
||||
};
|
||||
|
||||
ImportSequencer.prototype.tryRun = function() {
|
||||
while(this.imports.length > 0) {
|
||||
var importItem = this.imports[0];
|
||||
if (!importItem.isReady) {
|
||||
return;
|
||||
while(true) {
|
||||
while(this.imports.length > 0) {
|
||||
var importItem = this.imports[0];
|
||||
if (!importItem.isReady) {
|
||||
return;
|
||||
}
|
||||
this.imports = this.imports.slice(1);
|
||||
importItem.callback.apply(null, importItem.args);
|
||||
}
|
||||
this.imports = this.imports.slice(1);
|
||||
importItem.callback.apply(null, importItem.args);
|
||||
if (this.variableImports.length === 0) {
|
||||
break;
|
||||
}
|
||||
var variableImport = this.variableImports[0];
|
||||
this.variableImports = this.variableImports.slice(1);
|
||||
variableImport();
|
||||
}
|
||||
if (this._onSequencerEmpty) {
|
||||
this._onSequencerEmpty();
|
||||
|
||||
@@ -27,6 +27,7 @@ ImportVisitor.prototype = {
|
||||
}
|
||||
|
||||
this.isFinished = true;
|
||||
this._sequencer.tryRun();
|
||||
if (this.importCount === 0) {
|
||||
this._finish(error || this.error);
|
||||
}
|
||||
@@ -113,9 +114,13 @@ ImportVisitor.prototype = {
|
||||
var subFinish = function(e) {
|
||||
importVisitor.importCount--;
|
||||
|
||||
if (importVisitor.importCount === 0 && importVisitor.isFinished) {
|
||||
importVisitor._finish(e || importVisitor.error);
|
||||
} else if (e) {
|
||||
if (importVisitor.isFinished) {
|
||||
this._sequencer.tryRun();
|
||||
if (importVisitor.importCount === 0) {
|
||||
importVisitor._finish(e || importVisitor.error);
|
||||
}
|
||||
}
|
||||
if (e) {
|
||||
importVisitor.error = e;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user