You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Carlos Rovira <ca...@apache.org> on 2019/06/26 14:49:01 UTC

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
http://about.me/carlosrovira

Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
Hi Alex,

I finally solved in my latest commit.
Thanks for the guidance :)

Carlos

El mar., 2 jul. 2019 a las 17:00, Carlos Rovira (<ca...@apache.org>)
escribió:

> Hi Alex,
>
> ok, I understand now. You propose to do something like we do for
> Application but for Modules using the same kind of process but instead of
> adding to html head create a new .js to be added like _deps,js. I think
> that will be ok and even more efficient since all is done by compiler. I'll
> try to imagine how I can do that in the compiler. The only special case I
> can see is if we have the same Class in Application already, so compiler
> will put that link or script tag twice, one for App and again for
> each module using it.
>
> Thanks
>
>
> El mar., 2 jul. 2019 a las 7:18, Alex Harui (<ah...@adobe.com.invalid>)
> escribió:
>
>>
>>
>> On 7/1/19, 9:42 AM, "Carlos Rovira" <ca...@apache.org> wrote:
>>
>>     > So, inject_html in a module should do effectively the same thing,
>> except I
>>     > don't think a module needs to inject HTML,
>>
>>
>>     right, we don't want to do that will defeat the module's purpose of
>>     deferred loading. And moreover, we don't know which classes will have
>> in
>>     the module to be loaded, or a module can be never loaded
>>
>> I don't understand why we don't know which classes will need to be loaded
>> before the module.  The inject_html tells us, doesn't it?
>>
>>     > it can just take a list of urls to load as Script tags.  So, no
>> scanning
>>     > of files is necessary.
>>
>>
>>     The user could explicitly set the urls to load, but that seems to me
>> not a
>>     Royale solution. I as a user, expect to use a Class that represents a
>> JS
>>     library, and it should handle under the hood the necessary setup. I
>> have
>>     clear that is needed to make a good solution.
>>
>> What I am proposing is that someone does modify the compiler to detect
>> the inject_html in the module classes and generate a .JS file you can load
>> like the _deps.js file.  Upthread I pointed to where the code is to be
>> modified.  If you do not want to make those changes, you can hand code the
>> .JS file for now.
>>
>>
>> HTH,
>> -Alex
>>
>>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
Hi Alex,

ok, I understand now. You propose to do something like we do for
Application but for Modules using the same kind of process but instead of
adding to html head create a new .js to be added like _deps,js. I think
that will be ok and even more efficient since all is done by compiler. I'll
try to imagine how I can do that in the compiler. The only special case I
can see is if we have the same Class in Application already, so compiler
will put that link or script tag twice, one for App and again for
each module using it.

Thanks


El mar., 2 jul. 2019 a las 7:18, Alex Harui (<ah...@adobe.com.invalid>)
escribió:

>
>
> On 7/1/19, 9:42 AM, "Carlos Rovira" <ca...@apache.org> wrote:
>
>     > So, inject_html in a module should do effectively the same thing,
> except I
>     > don't think a module needs to inject HTML,
>
>
>     right, we don't want to do that will defeat the module's purpose of
>     deferred loading. And moreover, we don't know which classes will have
> in
>     the module to be loaded, or a module can be never loaded
>
> I don't understand why we don't know which classes will need to be loaded
> before the module.  The inject_html tells us, doesn't it?
>
>     > it can just take a list of urls to load as Script tags.  So, no
> scanning
>     > of files is necessary.
>
>
>     The user could explicitly set the urls to load, but that seems to me
> not a
>     Royale solution. I as a user, expect to use a Class that represents a
> JS
>     library, and it should handle under the hood the necessary setup. I
> have
>     clear that is needed to make a good solution.
>
> What I am proposing is that someone does modify the compiler to detect the
> inject_html in the module classes and generate a .JS file you can load like
> the _deps.js file.  Upthread I pointed to where the code is to be
> modified.  If you do not want to make those changes, you can hand code the
> .JS file for now.
>
>
> HTH,
> -Alex
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.

On 7/1/19, 9:42 AM, "Carlos Rovira" <ca...@apache.org> wrote:

    > So, inject_html in a module should do effectively the same thing, except I
    > don't think a module needs to inject HTML,
    
    
    right, we don't want to do that will defeat the module's purpose of
    deferred loading. And moreover, we don't know which classes will have in
    the module to be loaded, or a module can be never loaded
    
I don't understand why we don't know which classes will need to be loaded before the module.  The inject_html tells us, doesn't it?
    
    > it can just take a list of urls to load as Script tags.  So, no scanning
    > of files is necessary.
    
    
    The user could explicitly set the urls to load, but that seems to me not a
    Royale solution. I as a user, expect to use a Class that represents a JS
    library, and it should handle under the hood the necessary setup. I have
    clear that is needed to make a good solution.

What I am proposing is that someone does modify the compiler to detect the inject_html in the module classes and generate a .JS file you can load like the _deps.js file.  Upthread I pointed to where the code is to be modified.  If you do not want to make those changes, you can hand code the .JS file for now.


HTH,
-Alex    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
Hi Alex

El lun., 1 jul. 2019 a las 6:52, Alex Harui (<ah...@adobe.com.invalid>)
escribió:

> If inject_html works in the app, that's essentially because the app.js
> doesn't get loaded and run until the injected html is executed.
>
>
yeah, that's clear to me.



> So, inject_html in a module should do effectively the same thing, except I
> don't think a module needs to inject HTML,


right, we don't want to do that will defeat the module's purpose of
deferred loading. And moreover, we don't know which classes will have in
the module to be loaded, or a module can be never loaded


> it can just take a list of urls to load as Script tags.  So, no scanning
> of files is necessary.


The user could explicitly set the urls to load, but that seems to me not a
Royale solution. I as a user, expect to use a Class that represents a JS
library, and it should handle under the hood the necessary setup. I have
clear that is needed to make a good solution.


> The same inject_html mechanism would work in the app or module.  The way
> the _deps.js file is loaded before the main module.js loaded is an example
> of how to defer the loading and execution of module.js until other files
> are loaded.
>

Yes, I tried, and works. My only need right now is to know how I can get
all the classes and loop to find what classes implement the interface. Do
you know how I can do that? Right now is the only thing I need to finish
modules.

thanks



>
> HTH,
> -Alex
>
> On 6/30/19, 2:50 AM, "Carlos Rovira" <ca...@apache.org> wrote:
>
>     @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 (<
> carlosrovira@apache.org>)
>     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 (<ha...@gmail.com>)
>     > 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 <
> carlosrovira@apache.org>
>     >> 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
> (<aharui@adobe.com.invalid
>     >> >)
>     >> > 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" <ca...@apache.org>
> 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
>     >> (<aharui@adobe.com.invalid
>     >> >>> )
>     >> >>    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" <ca...@apache.org>
>     >> >> 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
>     >> >> (<aharui@adobe.com.invalid
>     >> >>>> )
>     >> >>>    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" <ca...@apache.org>
>     >> >>> 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 (<
>     >> >> harbs.lists@gmail.com
>     >> >>>> )
>     >> >>>> 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
>     >> >>> <aharui@adobe.com.INVALID
>     >> >>>>>
>     >> >>>>> 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" <
>     >> >>> carlosrovira@apache.org>
>     >> >>>> 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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=v58mAdSAMvmjqIT%2FdXExq%2FE8pgd2CTobXSVf0td1IBQ%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 (<
>     >> >>> aggspi@novusnet.gr
>     >> >>>>> )
>     >> >>>>> 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:carlosrovira@apache.org]
>     >> >>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
>     >> >>>>>>> To: dev@royale.apache.org
>     >> >>>>>>> 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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%3D&amp;reserved=0
>
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.
If inject_html works in the app, that's essentially because the app.js doesn't get loaded and run until the injected html is executed.

So, inject_html in a module should do effectively the same thing, except I don't think a module needs to inject HTML, it can just take a list of urls to load as Script tags.  So, no scanning of files is necessary.  The same inject_html mechanism would work in the app or module.  The way the _deps.js file is loaded before the main module.js loaded is an example of how to defer the loading and execution of module.js until other files are loaded.

HTH,
-Alex

On 6/30/19, 2:50 AM, "Carlos Rovira" <ca...@apache.org> wrote:

    @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 (<ca...@apache.org>)
    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 (<ha...@gmail.com>)
    > 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 <ca...@apache.org>
    >> 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 (<aharui@adobe.com.invalid
    >> >)
    >> > 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" <ca...@apache.org> 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
    >> (<aharui@adobe.com.invalid
    >> >>> )
    >> >>    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" <ca...@apache.org>
    >> >> 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
    >> >> (<aharui@adobe.com.invalid
    >> >>>> )
    >> >>>    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" <ca...@apache.org>
    >> >>> 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 (<
    >> >> harbs.lists@gmail.com
    >> >>>> )
    >> >>>> 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
    >> >>> <aharui@adobe.com.INVALID
    >> >>>>>
    >> >>>>> 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" <
    >> >>> carlosrovira@apache.org>
    >> >>>> 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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=v58mAdSAMvmjqIT%2FdXExq%2FE8pgd2CTobXSVf0td1IBQ%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 (<
    >> >>> aggspi@novusnet.gr
    >> >>>>> )
    >> >>>>> 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:carlosrovira@apache.org]
    >> >>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
    >> >>>>>>> To: dev@royale.apache.org
    >> >>>>>>> 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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477238074&amp;sdata=keyaoDCEVa2C0PeoFH8q5Wr9Od%2FLHbeH9COyJGEf3VE%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%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%7C3bd88a24ac3e4f14d11d08d6fd406978%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636974850477248068&amp;sdata=KPBQl1u%2BvpDz9CuprNCuwzayr64aU%2FofMm3rGUenT2I%3D&amp;reserved=0
    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
@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 (<ca...@apache.org>)
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 (<ha...@gmail.com>)
> 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 <ca...@apache.org>
>> 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 (<aharui@adobe.com.invalid
>> >)
>> > 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" <ca...@apache.org> 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
>> (<aharui@adobe.com.invalid
>> >>> )
>> >>    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" <ca...@apache.org>
>> >> 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
>> >> (<aharui@adobe.com.invalid
>> >>>> )
>> >>>    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" <ca...@apache.org>
>> >>> 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 (<
>> >> harbs.lists@gmail.com
>> >>>> )
>> >>>> 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
>> >>> <aharui@adobe.com.INVALID
>> >>>>>
>> >>>>> 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" <
>> >>> carlosrovira@apache.org>
>> >>>> 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 (<
>> >>> aggspi@novusnet.gr
>> >>>>> )
>> >>>>> 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:carlosrovira@apache.org]
>> >>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
>> >>>>>>> To: dev@royale.apache.org
>> >>>>>>> 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

Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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 (<ha...@gmail.com>) 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 <ca...@apache.org>
> 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 (<aharui@adobe.com.invalid
> >)
> > 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" <ca...@apache.org> 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
> (<aharui@adobe.com.invalid
> >>> )
> >>    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" <ca...@apache.org>
> >> 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
> >> (<aharui@adobe.com.invalid
> >>>> )
> >>>    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" <ca...@apache.org>
> >>> 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 (<
> >> harbs.lists@gmail.com
> >>>> )
> >>>> 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
> >>> <aharui@adobe.com.INVALID
> >>>>>
> >>>>> 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" <
> >>> carlosrovira@apache.org>
> >>>> 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 (<
> >>> aggspi@novusnet.gr
> >>>>> )
> >>>>> 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:carlosrovira@apache.org]
> >>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
> >>>>>>> To: dev@royale.apache.org
> >>>>>>> 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

Re: Trying to run a function on a class that is not instantiated

Posted by Harbs <ha...@gmail.com>.
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 <ca...@apache.org> 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 (<ah...@adobe.com.invalid>)
> 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" <ca...@apache.org> 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 (<aharui@adobe.com.invalid
>>> )
>>    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" <ca...@apache.org>
>> 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
>> (<aharui@adobe.com.invalid
>>>> )
>>>    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" <ca...@apache.org>
>>> 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 (<
>> harbs.lists@gmail.com
>>>> )
>>>> 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
>>> <aharui@adobe.com.INVALID
>>>>> 
>>>>> 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" <
>>> carlosrovira@apache.org>
>>>> 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 (<
>>> aggspi@novusnet.gr
>>>>> )
>>>>> 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:carlosrovira@apache.org]
>>>>>>> Sent: Wednesday, June 26, 2019 5:49 PM
>>>>>>> To: dev@royale.apache.org
>>>>>>> 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


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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 (<ah...@adobe.com.invalid>)
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" <ca...@apache.org> 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 (<aharui@adobe.com.invalid
> >)
>     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" <ca...@apache.org>
> 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
> (<aharui@adobe.com.invalid
>     > >)
>     >     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" <ca...@apache.org>
>     > 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 (<
> harbs.lists@gmail.com
>     > >)
>     >     > 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
>     > <aharui@adobe.com.INVALID
>     >     > >
>     >     >     > 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" <
>     > carlosrovira@apache.org>
>     >     > 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 (<
>     > aggspi@novusnet.gr
>     >     > >)
>     >     >     > 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:carlosrovira@apache.org]
>     >     >     > >> Sent: Wednesday, June 26, 2019 5:49 PM
>     >     >     > >> To: dev@royale.apache.org
>     >     >     > >> 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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.
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" <ca...@apache.org> 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 (<ah...@adobe.com.invalid>)
    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" <ca...@apache.org> 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 (<aharui@adobe.com.invalid
    > >)
    >     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" <ca...@apache.org>
    > 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 (<harbs.lists@gmail.com
    > >)
    >     > 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
    > <aharui@adobe.com.INVALID
    >     > >
    >     >     > 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" <
    > carlosrovira@apache.org>
    >     > 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 (<
    > aggspi@novusnet.gr
    >     > >)
    >     >     > 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:carlosrovira@apache.org]
    >     >     > >> Sent: Wednesday, June 26, 2019 5:49 PM
    >     >     > >> To: dev@royale.apache.org
    >     >     > >> 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
    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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 (<ah...@adobe.com.invalid>)
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" <ca...@apache.org> 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 (<aharui@adobe.com.invalid
> >)
>     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" <ca...@apache.org>
> 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 (<harbs.lists@gmail.com
> >)
>     > 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
> <aharui@adobe.com.INVALID
>     > >
>     >     > 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" <
> carlosrovira@apache.org>
>     > 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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=13kFGAeYPKv3uETc3J%2F8zzV0M%2F3jdWM5TdvtDneVu7w%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 (<
> aggspi@novusnet.gr
>     > >)
>     >     > 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:carlosrovira@apache.org]
>     >     > >> Sent: Wednesday, June 26, 2019 5:49 PM
>     >     > >> To: dev@royale.apache.org
>     >     > >> 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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%3D&amp;reserved=0
>
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.
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" <ca...@apache.org> 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 (<ah...@adobe.com.invalid>)
    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" <ca...@apache.org> 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 (<ha...@gmail.com>)
    > 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 <aharui@adobe.com.INVALID
    > >
    >     > 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" <ca...@apache.org>
    > 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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=13kFGAeYPKv3uETc3J%2F8zzV0M%2F3jdWM5TdvtDneVu7w%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 (<aggspi@novusnet.gr
    > >)
    >     > 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:carlosrovira@apache.org]
    >     > >> Sent: Wednesday, June 26, 2019 5:49 PM
    >     > >> To: dev@royale.apache.org
    >     > >> 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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%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%7C0fba1437b370405d8d0208d6fc1576b0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636973566476749021&amp;sdata=vgPgFnpmCTXvuRubkZu9ypRKe7SukeRF2ean2ytFKfQ%3D&amp;reserved=0
    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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 (<ah...@adobe.com.invalid>)
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" <ca...@apache.org> 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 (<ha...@gmail.com>)
> 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 <aharui@adobe.com.INVALID
> >
>     > 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" <ca...@apache.org>
> 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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882055963&amp;sdata=q6PWd4TcVwmnVlw2djwDKSvteiVT8dzrW104mzuV%2FUw%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 (<aggspi@novusnet.gr
> >)
>     > 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:carlosrovira@apache.org]
>     > >> Sent: Wednesday, June 26, 2019 5:49 PM
>     > >> To: dev@royale.apache.org
>     > >> 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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%3D&amp;reserved=0
>
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.
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" <ca...@apache.org> 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 (<ha...@gmail.com>) 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 <ah...@adobe.com.INVALID>
    > 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" <ca...@apache.org> 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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882055963&amp;sdata=q6PWd4TcVwmnVlw2djwDKSvteiVT8dzrW104mzuV%2FUw%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 (<ag...@novusnet.gr>)
    > 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:carlosrovira@apache.org]
    > >> Sent: Wednesday, June 26, 2019 5:49 PM
    > >> To: dev@royale.apache.org
    > >> 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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%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%7C68f075afc18547f7037c08d6fafa6fd0%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636972350882065960&amp;sdata=LdKimckgxxIWf5VObhdXV9%2BgEzAH403uv%2F1Okz7SfP0%3D&amp;reserved=0
    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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 (<ha...@gmail.com>) 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 <ah...@adobe.com.INVALID>
> 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" <ca...@apache.org> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001069684&amp;sdata=5KVxS4gVhXKdEWWOyG3xmHXTPKNV70OPkE7bCZsYn0g%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 (<ag...@novusnet.gr>)
> 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:carlosrovira@apache.org]
> >> Sent: Wednesday, June 26, 2019 5:49 PM
> >> To: dev@royale.apache.org
> >> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%3D&amp;reserved=0
> >
> >
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Harbs <ha...@gmail.com>.
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 <ah...@adobe.com.INVALID> 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" <ca...@apache.org> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001069684&amp;sdata=5KVxS4gVhXKdEWWOyG3xmHXTPKNV70OPkE7bCZsYn0g%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 (<ag...@novusnet.gr>) 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:carlosrovira@apache.org]
>> Sent: Wednesday, June 26, 2019 5:49 PM
>> To: dev@royale.apache.org
>> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%3D&amp;reserved=0
> 
> 


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
Hi Alex,

in this concrete use case (a basic module scenario), I can confirm a
preloader is not necessary, since I tested the code and it works fine.
My problem is different. I want the user to avoid a call to loadCSS, since
just using the MaterialIconType Royale should add implicitly the link tag
to head.

I'm sure that a preloader will be needed more more complex scenarios, but I
think that should be other blog post that address that. For now, I'm just
trying to do the first and most basic one.



El jue., 27 jun. 2019 a las 9:29, Alex Harui (<ah...@adobe.com.invalid>)
escribió:

> I'm pretty sure in related threads I mentioned that a preloader is needed.
>
> -Alex
>
> On 6/26/19, 8:16 AM, "Carlos Rovira" <ca...@apache.org> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001069684&amp;sdata=5KVxS4gVhXKdEWWOyG3xmHXTPKNV70OPkE7bCZsYn0g%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 (<ag...@novusnet.gr>)
> 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:carlosrovira@apache.org]
>     > Sent: Wednesday, June 26, 2019 5:49 PM
>     > To: dev@royale.apache.org
>     > 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%3D&amp;reserved=0
>
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Alex Harui <ah...@adobe.com.INVALID>.
I'm pretty sure in related threads I mentioned that a preloader is needed.

-Alex

On 6/26/19, 8:16 AM, "Carlos Rovira" <ca...@apache.org> 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001069684&amp;sdata=5KVxS4gVhXKdEWWOyG3xmHXTPKNV70OPkE7bCZsYn0g%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 (<ag...@novusnet.gr>) 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:carlosrovira@apache.org]
    > Sent: Wednesday, June 26, 2019 5:49 PM
    > To: dev@royale.apache.org
    > 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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%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%7C25b97d52ac98496b4e9a08d6fa49476e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636971590001079678&amp;sdata=kd8i%2FuPoxvRf9f%2FLW2DSgk6yvnBdtgKtRkP%2BeRIj%2FWs%3D&amp;reserved=0
    


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
Hi Harbs,

thanks for the suggestion. Yes, I remember that function that is very
convenient. But can't be use in this concrete use case.
I want the user use MaterialIconType class as always, and that's just bind
to one of the constants in the class. In the application, the inject_html
is processed, in the module it's not. So I only need to add the "link" tag
to the head section when I use MaterialIconType in a module, and avoid
users to explicitly need to do a call to loadCSS (or if the need is JS, a
call to loadJavascript)

El jue., 27 jun. 2019 a las 9:58, Harbs (<ha...@gmail.com>) escribió:

> Have you looked at addDynamicSelector()?
>
> > On Jun 26, 2019, at 6:16 PM, Carlos Rovira <ca...@apache.org>
> wrote:
> >
> > I created as well "loadCSS" (still not commited).
>
>

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

Re: Trying to run a function on a class that is not instantiated

Posted by Harbs <ha...@gmail.com>.
Have you looked at addDynamicSelector()?

> On Jun 26, 2019, at 6:16 PM, Carlos Rovira <ca...@apache.org> wrote:
> 
> I created as well "loadCSS" (still not commited).


Re: Trying to run a function on a class that is not instantiated

Posted by Carlos Rovira <ca...@apache.org>.
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://fonts.googleapis.com/icon?family=Material+Icons');

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 (<ag...@novusnet.gr>) 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:carlosrovira@apache.org]
> Sent: Wednesday, June 26, 2019 5:49 PM
> To: dev@royale.apache.org
> 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
> http://about.me/carlosrovira
>
>

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

RE: Trying to run a function on a class that is not instantiated

Posted by spiros <ag...@novusnet.gr>.
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:carlosrovira@apache.org] 
Sent: Wednesday, June 26, 2019 5:49 PM
To: dev@royale.apache.org
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
http://about.me/carlosrovira