Skip to content

Commit

Permalink
introduce rootPlan and test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomohito Nakayama committed Mar 18, 2016
1 parent c42e7b9 commit 497f58b
Showing 1 changed file with 68 additions and 24 deletions.
92 changes: 68 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ jf.roots =
return addErrorListener( new rootsExecuter(rootExecuters), errListener);
}

jf.event =
function( eventListnerCongigurator, fileNameCalculator, errListener ){
return addErrorListener(
new eventExecuter(
eventListenerConfigurator,
fileNameCalculator ),
errListener
);
}

function executer( parent ){

this.parent = parent;
Expand Down Expand Up @@ -199,6 +209,14 @@ function collectPlan( executer )

}

function rootPlan( executeFunction , fixedFile ){
executePlan.call( this, executeFunction );
this.fixedFiles = fixedFile;
}

util.inherits( collectPlan, executePlan );
util.inherits( rootPlan, executePlan );

function runtimeInformation(){

let jsonFilesInProgress = new Map();
Expand Down Expand Up @@ -252,7 +270,7 @@ function filedExecuter( file ){

this.rootExec =
function(executePlan){
executePlan._executeFunction()
executePlan._executeFunction();
};

this.file = () => file;
Expand Down Expand Up @@ -295,6 +313,16 @@ function rootsExecuter( executers ){

};

function eventExecuter( eventListnerCongigurator, fileNameCalculator ){
rootExecuter.call( this, null );
let thisExecuter = this;

this.rootExec =
function( executePlan ){
executePlan._executeFunction();
};

}

function childExecuter( userProcess, parent ){

Expand All @@ -312,13 +340,16 @@ function childExecuter( userProcess, parent ){
}




function createPlan( executer ){

if( executer instanceof newFileExecuter ) return createNewFilePlan( executer );
else if( executer instanceof filedExecuter ) return createFiledPlan( executer );
else if( executer instanceof downloadExecuter ) return createDownloadPlan(executer);
else if( executer instanceof collectExecuter ) return new collectPlan(executer);
else if( executer instanceof rootsExecuter ) return createRootsPlan(executer);
else if( executer instanceof eventExecuter ) return createEventPlan( executer );
else return createChildPlan( executer );
}

Expand Down Expand Up @@ -370,21 +401,17 @@ function createFilePlanCore( executeForFile, executer ){

if( executer.file() != null ){

let plan = new executePlan(
let plan = new rootPlan(
function(){

let jsonFilesArray = Array.from( this.fixedFiles );
jsonFilesArray.forEach( this.runtime.addJsonFile, this.runtime);

for( let jsonFile of jsonFilesArray ){
executeForFile( jsonFile, this );
}

}
},
fixFiles( executer.file() )
);

plan.fixedFiles = fixFiles( executer.file() );

return plan;

} else {
Expand All @@ -396,7 +423,7 @@ function createFilePlanCore( executeForFile, executer ){


function createDownloadPlan( executer ){
let plan = new executePlan(
let plan = new rootPlan(

function(){
let thisPlan = this;
Expand Down Expand Up @@ -432,11 +459,10 @@ function createDownloadPlan( executer ){
err => { executer.emit( err ) }
).exec();
}
}
},
fixFiles( executer.file() )
);

plan.fixedFiles = fixFiles( executer.file() );

return plan;

}
Expand All @@ -446,8 +472,18 @@ function createRootsPlan( rootsExecuter ){
let executers = rootsExecuter.executers();
let plans =
Array.from( executers, createPlan );
//fix files for rootsPlan
let files = [];
plans.forEach(
plan =>{
plan.fixedFiles.forEach(
file => { files.push( file ); }
)
}
);


let rootsPlan = new executePlan(
let rootsPlan = new rootPlan(

function(){

Expand All @@ -463,19 +499,10 @@ function createRootsPlan( rootsExecuter ){
plan._executeFunction();

}
}
);

//fix files for rootsPlan
var files = [];
plans.forEach(
plan =>{
files = files.concat( plan.fixedFiles );
}
},
files
);

rootsPlan.fixedFiles = files;

return rootsPlan;

}
Expand Down Expand Up @@ -517,6 +544,23 @@ function multiplePath( files ){
return Array.from(files, path => new JsonFile( path ));
}

function createEventPlan( executer ){

let plan = new executePlan(
function(){

let jsonFilesArray = Array.from( this.fixedFiles );
jsonFilesArray.forEach( this.runtime.addJsonFile, this.runtime);

for( let jsonFile of jsonFilesArray ){
executeForFile( jsonFile, this );
}

}
);

}

// Historycally JsonFile was developed substituting filePath of plain String.
// So in several parts, JsonFile object is handled in variable named xxxxPath.
function JsonFile( filePath ){
Expand Down

0 comments on commit 497f58b

Please sign in to comment.