1

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.

1 Answer 1

1

You need to quote your begin and end properties. You are currently referencing them both as quoted properties and as dotted which violates the property renaming restrictions of ADVANCED_OPTIMIZATIONS. See Implications of global variable, function, and property renaming

var where={begin:"",end:""}, //unquoted - quote these to fix

where[whereTo]=... //quoted
2
  • Thank you Chad, makes sense. Now that I am aware of what caused the problem I'll try to add goog.require to my files and remove some of the --input from cacldeps.py parameters. Have to set a goog.require in the order of how the files are called. DomDependent is called first to attach events to mediator so I'll set a goog.require there to WorkFlow.
    – HMR
    Commented Apr 27, 2013 at 0:38
  • I've added the myApp.Classes in deps.js, now I only add goog.require ("myApp.DomDependent") and uncompiled code works. Compiled code works because (for example) DomDependent has goog.require('myApp.WorkFlow'). It starts with DomDependent because that has the function that's firs called on page load.
    – HMR
    Commented Apr 27, 2013 at 1:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.