I have several objects; one is called DomDependent one is called WorkFlow one is called mediator.
The domdependent has the following code:
myApp.DomDependent.attachEvents=function(){
myApp.mediator.attach("doConversion",mmt.WorkFlow.doConversion);
DomDependent registers "events" on the mediator and WorkFlow has the functions to implement them. When I compile the code with WorkFlow listed after DomDependent the events get registered but functions are null. When I compile with WorkFlow listed before DomDependent some events won't get registered at all and some do with function to implement them.
I'm not sure what is the right way to implement circular dependencies as the WorkFlow object makes call to Domdependent as well to get textbox values and such:
From WorkFlow:
myApp.DomDependent.removeAdded();
I've tried to put a goog.require in both DomDependent (to WorkFlow) and in WorkFlow to DomDependent but it won't compile at all due to circular dependencies.
So removed the goog.require statements to myApp in the files and provided them as command line arguments to calcdeps.py:
set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\ ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\myApp\Mediator.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\myApp\WorkFlow.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\myApp\data.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\myApp\Messenger.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\myApp\DomDependent.js ^
--compiler_jar "D:\software\closure compiler\compiler.jar" ^
--output_mode compiled ^
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
--compiler_flags="--formatting=PRETTY_PRINT" ^
--compiler_flags="--warning_level=VERBOSE" ^
--output_file D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\main.js
pause
My questions are:
Is this the right way to get dependency? If I opt for goog.require
in DomDependent then all of the code in WorkFlow is removed and triggering any of the events registered with mediator will try to call undefined.
How can I make sure that the functions are not removed, they are called through the mediator but I think compiler misses a couple of them and I have yet to find out why. Uncompiled code works but after compilation the mediator tries to call unexisting functions (mediator is compiled as well so it's not the renaming functions part).
[UPDATE]
Found out the one bug where I suspected event wasn't registered. It is registered but doesn't do anything because of renaming variables. For example this function that adds text either to beginning or end of a line:
myApp.WorkFlow.addBegin=function(){
myApp.WorkFlow.addEndOrBegin("begin");
};
myApp.WorkFlow.addEndOrBegin=function(whereTo){
var where={begin:"",end:""},
lines=myApp.DomDependent.getAddwordsContent(false).split("\n"),
i;
where[whereTo]=mmt.DomDependent.getBeginEnd();
for(i=0;i<lines.length;i++){
lines[i]=where.begin+lines[i]+where.end;
...
In compiled version the where object variable doesn't have begin and end properties so where["begin"] doesn't exist or is undefined.
I would still like to know what the right way is to compile circular dependent files.