@Harbs, A final thought, as you can see in the problem described, I don't
want the user, or Module or Application knows about any setup. I just want
that knowledge is in the Class itself and be performed just by implementing
"IModuleInfo" in its "setup()" method.

El dom., 30 jun. 2019 a las 11:47, Carlos Rovira (<[email protected]>)
escribió:

> Hi Harbs,
>
> thanks for proposal, but I think still the problem is not clear enough
> what is causing confusion. I think we have actually the capability to chain
> actions with events as the module load (description of the process below).
> What I'm pursuing is that a Royale Class present in a Module can perform
> some initialization setup.
>
> I think the issue is in Basic UIModuleUtils, that makes the following
> process to load a module:
>
> 1.- *loadModule()* -> is what ModuleLoader calls to start the process
>
>        a.- *createLoader()*  -->  this creates "link" and "script" tags
> of the module. Following methods are call "onLoad"
>
>                - Only for DEBUG:  *loadDepsHandler()*  , setTImeout and
> then call 3b loadHander
>
>               -  Only for RELEASE:  *loadHandler()* , *here's where we
> create the instance of the main class of the Module and add to the parent.*
>
>               -  *actuallyLoadModule() *, triggered as the CSS in loadCSS
> is loaded.
>
>        b.- *loadCSS()*        --->  this fills the CSS "link" tag of the
> module
>
> Notice that link and script tags setup there are all well known and
> related to the normal structure of the module, what we'll want to set up
> are the ones present in the classes to be loaded from the module at later
> time.
>
> I think the point where we need to act in loadHandler() just before we add
> the Main module class to the parent.
> In that point we have all classes loaded, but still are not playing in our
> App.
> So There (and this can be PAYG using a UIModuleUtils extension), I want to
> discover what classes loaded has a "IModuleInfo" interface and call
> "setup()" method in those ones).
>
> Hope, I explained it better and make more sense now.
>
>
>
>
>
>
>
>
> El dom., 30 jun. 2019 a las 11:10, Harbs (<[email protected]>)
> escribió:
>
>> What about another approach?
>>
>> Maybe modules can have a two-step initialization:
>> 1. If there are dependencies, those are loaded with a callback.
>> 2. Once all the dependencies are loaded, the module is actually
>> initialized and dispatches some events.
>>
>> That way, the parent application does not need to know about the modules
>> classes.
>>
>> > On Jun 30, 2019, at 11:59 AM, Carlos Rovira <[email protected]>
>> wrote:
>> >
>> > Hi Alex,
>> >
>> > ok, then can we?
>> >
>> > 1.- *load the module (*but still not add it to app, so no start to run)
>> > 2.- *inspect the classes loaded in the module* to know what of them
>> > implements a concrete interface (let's call "IModuleInfo")
>> > 3.- *set up script and link tags* but running IModuleInfo.setup() in all
>> > classes in the module
>> > 4.- *add the module* to parent so it can start running
>> >
>> > If that's ok, for me the tricky part is how to loop over the loaded
>> classes
>> > to know the ones that implements IModuleInfo and make a call to setup()
>> > method.
>> >
>> > Point 2 and 3 could be PAYG so it could be added to the module as a
>> bead.
>> >
>> >
>> > El dom., 30 jun. 2019 a las 8:13, Alex Harui (<[email protected]
>> >)
>> > escribió:
>> >
>> >> The whole reason for inject_html is so some 3rd party JS can be loaded
>> >> before Royale JS code starts using it.  Because the loading of the
>> >> 3rd-party code is a server request and possibly asynchronous, I don't
>> think
>> >> we want a pattern where the class that needs some 3rd party code tries
>> to
>> >> load that code in its initializers.  That's not now it works in the
>> main
>> >> app, so I don't see why it has to work this way in the modules.  Just
>> have
>> >> the module set up script tags to load the 3rd party JS before the
>> module's
>> >> JS gets loaded.
>> >>
>> >> My 2 cents,
>> >> -Alex
>> >>
>> >> On 6/29/19, 3:27 PM, "Carlos Rovira" <[email protected]> wrote:
>> >>
>> >>    Hi Alex,
>> >>
>> >>    yes the solution is that, so to add dynamically a css or javascript
>> I
>> >> want
>> >>    to do the same way you did in UIModuleUtils.createLoader(), where
>> you
>> >>    create a "link" element or a "script" element.
>> >>    What I really ask is how to trigger a method like that in (lets say)
>> >>    package.MyClass when a user uses that concrete class, and avoiding
>> the
>> >> user
>> >>    explicitly call that method (that's how I set up temporary in the
>> blog
>> >>    example).
>> >>
>> >>    if user wants to do in a Module this:
>> >>
>> >>    import package.MyClass; MyClass;
>> >>
>> >>    And the in some part uses just a public static var like this:
>> >>
>> >>    var p:String = MyClass.SOME_PUBLIC_STATIC_VAR;
>> >>
>> >>    I want Royale runs a function (that will be something like the part
>> of
>> >> the
>> >>    code in UIModuleUtils.createLoader(), where we create a "link" or
>> >> "script"
>> >>    element and those get added to the html head.
>> >>
>> >>    In the real world example the class is just a proxy to a Material
>> >> Icons CSS
>> >>    and when using a classname and a text we get the icon. So in Royale,
>> >> the
>> >>    user will just need to use the class as always in a binding or
>> >> assignment
>> >>    using something like MyClass.SOME_PUBLIC_STATIC_VAR. And until now
>> we
>> >> was
>> >>    getting the CSS linked in the HTML thanks to compiler processing
>> with
>> >>    inject_html directive. With Modules I don't see right now a way to
>> do
>> >> this
>> >>    in a transparent way for the user, and making him to add a call in
>> his
>> >>    code, seems not a Royale way. That should be a framework call since
>> is
>> >>    clear that tthe user is using a var just to print a text and get an
>> >> icon.
>> >>
>> >>    I think I have a solution for this: I remember in Flex days that we
>> had
>> >>    something called MIXINS. If I recall correctly that MIXINGS was
>> >> triggered
>> >>    in a class that implement Mixing interface and then SytemManager
>> run a
>> >>    method in that class. I think we can do the same here. If you think
>> is
>> >> ok,
>> >>    to perform this, the solution could be that Module will hold
>> >> automatically
>> >>    a registry of classes that implements a interface. Then when load we
>> >> can
>> >>    call on the classes of that registry a method of the interface that
>> >> will
>> >>    add the necessary "script" or "link" tags to html. If the class is
>> >> used in
>> >>    Application, then inject_html does the right work, if is used in
>> >> Module,
>> >>    when module loads it calls the method an solves the problem.
>> >>
>> >>    What do you think? Don't see other way to solve this.
>> >>
>> >>
>> >>    El sáb., 29 jun. 2019 a las 8:19, Alex Harui
>> (<[email protected]
>> >>> )
>> >>    escribió:
>> >>
>> >>> Take a look at UIModuleLoader and UIModuleUtils.  Already it creates
>> >>> several HTML script and link tags to load a js-debug module.  The
>> >> patterns
>> >>> are already there to use as a template to load another script tag
>> >> that will
>> >>> add other script tags to the DOM or do just about anything you
>> >> want.   You
>> >>> can manually code that additional JS file or have the compiler
>> >> autogenerate
>> >>> it from addtionalHTML.  I don't think you want to generate HTML and
>> >> write
>> >>> it to innerHTML, but I could be wrong about that.
>> >>>
>> >>> In the compiler, the MXMLRoyalePublisher is where the inject_html
>> >> data is
>> >>> represented as additionalHTML and can be modified to be working JS.
>> >>>
>> >>> HTH,
>> >>> -Alex
>> >>>
>> >>> On 6/28/19, 3:10 PM, "Carlos Rovira" <[email protected]>
>> >> wrote:
>> >>>
>> >>>    For watt you say, I'm more with the second part of your response
>> >> where
>> >>> we
>> >>>    can alter the compiler to modify the additionalHTML, but I think
>> >> that
>> >>>    should be based on inject_html like we do in Application. I
>> >> remember
>> >>> that
>> >>>    this problem is less related to a loading of resources problem,
>> >> that we
>> >>>    need to wait until the bytes was completely downloaded and we
>> >> signaled
>> >>> that
>> >>>    event. This is more an Annotation-metadata problem where we want
>> >> that
>> >>> if
>> >>>    the user *use* a class we want the html gets decorated with a
>> >> line of
>> >>> code,
>> >>>    and that should happen only once as currently happens when we
>> >> use the
>> >>> same
>> >>>    class in the Application.
>> >>>
>> >>>    but If I try. to imagine how to do that, I don't get any idea,
>> >> since
>> >>> that
>> >>>    can be done like we do with main application. In this case, we
>> >> only
>> >>> can add
>> >>>    to the HTML once the user loads the module and that means can't
>> >> be a
>> >>>    preprocess in the compiler like is actually in application
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>    El sáb., 29 jun. 2019 a las 0:01, Alex Harui
>> >> (<[email protected]
>> >>>> )
>> >>>    escribió:
>> >>>
>> >>>> In a quick peek at the code, the ModuleLoader already loads
>> >> more
>> >>> than one
>> >>>> file.  It should be relatively simple to have a subclass or
>> >> alternate
>> >>>> ModuleLoaderWithPreloader that loads an additional file that
>> >> loads
>> >>> the
>> >>>> third-party JS.
>> >>>>
>> >>>> Also, it appears that it should be relatively simple to alter
>> >> the
>> >>> compiler
>> >>>> to take the additionalHTML and output it to be that additional
>> >> file.
>> >>>>
>> >>>> -Alex
>> >>>>
>> >>>> On 6/27/19, 5:24 AM, "Carlos Rovira" <[email protected]>
>> >>> wrote:
>> >>>>
>> >>>>    I'm with you that we can make the compiler optimize the
>> >> class
>> >>> and just
>> >>>> add
>> >>>>    the constants used, but I think that's is just an
>> >> optimization
>> >>> issue. A
>> >>>>    user will want to use constants this way. They even could
>> >> create
>> >>> a
>> >>>> reduced
>> >>>>    class with just the constants he needs.
>> >>>>
>> >>>>    About preloader, I'm interested in see how to do it. Maybe
>> >> some
>> >>> example
>> >>>>    from you and Yshay could be great to add to blog examples,
>> >> I can
>> >>> help
>> >>>> with
>> >>>>    that If you want, if you provide an email with the code, or
>> >>> prepare a
>> >>>>    project, I can do the rest. It would be good to all of us,
>> >> so we
>> >>> can
>> >>>> learn
>> >>>>    how to do it.
>> >>>>
>> >>>>    But as I stated before in my response to Alex, I don't
>> >> think the
>> >>>> preloader
>> >>>>    is the real problem in this case. Although we use a
>> >> preloader, I
>> >>> think
>> >>>> we
>> >>>>    still need to solve the inject_html issue in modules don't
>> >> you
>> >>> think?
>> >>>>
>> >>>>
>> >>>>
>> >>>>    El jue., 27 jun. 2019 a las 10:05, Harbs (<
>> >> [email protected]
>> >>>> )
>> >>>> escribió:
>> >>>>
>> >>>>> I also don’t know that abstracting this too much is a
>> >> good
>> >>> thing.
>> >>>> It’s a
>> >>>>> fair trade-off to require declaring external
>> >> dependencies. It
>> >>> also
>> >>>> allows
>> >>>>> for controlling where the dependencies are coming from,
>> >>> versioning,
>> >>>> etc.
>> >>>>>
>> >>>>> To me the pattern should be something like this:
>> >>>>>
>> >>>>> 1. Add a preloader bead to the app.
>> >>>>> 2. Declare a list of dependencies for the preloader
>> >> (which can
>> >>>> control
>> >>>>> where these dependencies are loaded from).
>> >>>>>
>> >>>>> In the case of something like MaterialIconType.SEARCH, I
>> >> don’t
>> >>> think
>> >>>> the
>> >>>>> MaterialIconType class should be included in the final
>> >> app at
>> >>> all if
>> >>>> all
>> >>>>> that’s used is some constants. I hope we eventually
>> >> optimize
>> >>> away all
>> >>>>> constants in the compiler.
>> >>>>>
>> >>>>> Harbs
>> >>>>>
>> >>>>>> On Jun 27, 2019, at 10:29 AM, Alex Harui
>> >>> <[email protected]
>> >>>>>
>> >>>>> wrote:
>> >>>>>>
>> >>>>>> I'm pretty sure in related threads I mentioned that a
>> >>> preloader is
>> >>>>> needed.
>> >>>>>>
>> >>>>>> -Alex
>> >>>>>>
>> >>>>>> On 6/26/19, 8:16 AM, "Carlos Rovira" <
>> >>> [email protected]>
>> >>>> wrote:
>> >>>>>>
>> >>>>>>   Thanks Spiros,
>> >>>>>>
>> >>>>>>   My real problem is the following. I'm trying to
>> >> improve
>> >>>> Modules. I
>> >>>>> found
>> >>>>>>   that inject_html don't work with modules,
>> >> Inject_html is
>> >>>> processed by
>> >>>>>>   compiler. To solve in an easy way I'm trying to
>> >> load CSS
>> >>> and JS
>> >>>> with
>> >>>>>>   javascript appending to head.
>> >>>>>>
>> >>>>>>   When I load the module and I use a class that needs
>> >> to
>> >>> attach
>> >>>> some
>> >>>>> JS, I
>> >>>>>>   want to run a function like "loadJavascript"
>> >>>>>>
>> >>>>>>   I created as well "loadCSS" (still not commited).
>> >>>>>>
>> >>>>>>   The real use case I'm trying is to use
>> >> MaterialIconType,
>> >>> that
>> >>>> was
>> >>>>> using
>> >>>>>>   inject_html. I removed the inject_html directive,
>> >>>>>>   then added
>> >>>>>>
>> >>>>>>   loadCSS('
>> >>>>>
>> >>>>
>> >>>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Ffonts.googleapis.com%2Ficon%3Ffamily%3DMaterial%2BIcons&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728139862&amp;sdata=%2F%2FiVExFORoM2EZb6RAQ8YbQ9bm243SGXnGmZCRouJZM%3D&amp;reserved=0
>> >>>> '
>> >>>>> );
>> >>>>>>
>> >>>>>>   in the constructor
>> >>>>>>
>> >>>>>>   then in my real module I want just to use as always
>> >>>>>>
>> >>>>>>   <js:FontIcon text="{MaterialIconType.SEARCH}"
>> >>> material="true"/>
>> >>>>>>
>> >>>>>>   accesing this way does not run the constructor, so
>> >> the
>> >>> loadCSS
>> >>>> code
>> >>>>> does
>> >>>>>>   not run :(
>> >>>>>>
>> >>>>>>
>> >>>>>>   We have hundreds of public static vars like
>> >>>>>>
>> >>>>>>   public static const SEARCH:String = 'search';
>> >>>>>>
>> >>>>>>   So I think the current way you propose, although
>> >> valid,
>> >>> will
>> >>>> not be
>> >>>>> the
>> >>>>>>   best here, since will means lots of lines of code.
>> >>>>>>
>> >>>>>>   But thanks for your suggestion
>> >>>>>>
>> >>>>>>   Hope others could give as well some ideas on how to
>> >> solve
>> >>> this
>> >>>>>>
>> >>>>>>   thanks
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>   El mié., 26 jun. 2019 a las 17:05, spiros (<
>> >>> [email protected]
>> >>>>> )
>> >>>>> escribió:
>> >>>>>>
>> >>>>>>> It is possible with static getter and seter.
>> >>>>>>>
>> >>>>>>> Maybe will help you the code below
>> >>>>>>>
>> >>>>>>> Spiros.
>> >>>>>>>
>> >>>>>>> public class Variable
>> >>>>>>>       {
>> >>>>>>>
>> >>>>>>>               private static var _textData:String;
>> >>>>>>>
>> >>>>>>>               public static function get
>> >> textData():String
>> >>>>>>>               {
>> >>>>>>>                       if( _textData ==null)
>> >>>>>>>                       {
>> >>>>>>>                               initailizeVariable();
>> >>>>>>>                       }
>> >>>>>>>                       return _textData;
>> >>>>>>>               }
>> >>>>>>>
>> >>>>>>>               public static function set
>> >>>> textData(value:String):void
>> >>>>>>>               {
>> >>>>>>>                       _textData = value;
>> >>>>>>>               }
>> >>>>>>>
>> >>>>>>>               public static function
>> >>> initailizeVariable():void
>> >>>>>>>               {
>> >>>>>>>                       _textData = "The quick brown
>> >> fox
>> >>> jump over
>> >>>> the
>> >>>>>>> lazy dog.";
>> >>>>>>>               }
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>               public function Variable()
>> >>>>>>>               {
>> >>>>>>>               }
>> >>>>>>>       }
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> -----Original Message-----
>> >>>>>>> From: Carlos Rovira [mailto:[email protected]]
>> >>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
>> >>>>>>> To: [email protected]
>> >>>>>>> Subject: Trying to run a function on a class that is
>> >> not
>> >>>> instantiated
>> >>>>>>>
>> >>>>>>> Hi,
>> >>>>>>>
>> >>>>>>> I need to run a function when I access a public
>> >> static var
>> >>> in a
>> >>>> class.
>> >>>>>>> Trying to run the function in the constructor seems
>> >> not to
>> >>> work
>> >>>> since
>> >>>>>>> there's no instance of that class. Do we have some
>> >> way to
>> >>> do this?
>> >>>>>>>
>> >>>>>>> --
>> >>>>>>> Carlos Rovira
>> >>>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728139862&amp;sdata=WgdK5dA3My%2BkuV5%2BbGqhP5QVZdEl4p0ae%2FB69YBV5YQ%3D&amp;reserved=0
>> >>>>>>>
>> >>>>>>>
>> >>>>>>
>> >>>>>>   --
>> >>>>>>   Carlos Rovira
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728139862&amp;sdata=WgdK5dA3My%2BkuV5%2BbGqhP5QVZdEl4p0ae%2FB69YBV5YQ%3D&amp;reserved=0
>> >>>>>>
>> >>>>>>
>> >>>>>
>> >>>>>
>> >>>>
>> >>>>    --
>> >>>>    Carlos Rovira
>> >>>>
>> >>>>
>> >>>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728149855&amp;sdata=nyev5XLQQy49d3rbRH4EXN4z1KYu0hTC4eSCRUIutHQ%3D&amp;reserved=0
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>>    --
>> >>>    Carlos Rovira
>> >>>
>> >>>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728149855&amp;sdata=nyev5XLQQy49d3rbRH4EXN4z1KYu0hTC4eSCRUIutHQ%3D&amp;reserved=0
>> >>>
>> >>>
>> >>>
>> >>
>> >>    --
>> >>    Carlos Rovira
>> >>
>> >>
>> https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fabout.me%2Fcarlosrovira&amp;data=02%7C01%7Caharui%40adobe.com%7C87fb43d241c445ea599f08d6fce102e7%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974440728149855&amp;sdata=nyev5XLQQy49d3rbRH4EXN4z1KYu0hTC4eSCRUIutHQ%3D&amp;reserved=0
>> >>
>> >>
>> >>
>> >
>> > --
>> > Carlos Rovira
>> > http://about.me/carlosrovira
>>
>>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>
>

-- 
Carlos Rovira
http://about.me/carlosrovira

Reply via email to