Quantcast

Re: Static method in property init

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Static method in property init

Fabian Jakobs
Administrator
Hi Kanugula,

> Hi,
>
> Why is this not working?
>
> qx.Class.define("myGui",
> {
>     extend : myAbstractGui,
>
>     properties :
>     {
>  rpcUrl :
>  {
>    init :
> my.ServerConfig.getServiceUrl()+"?request=delete&system=mySystem",
>  nullable : false
>  }
>    },
>
> }
>
> qx.Class.define("my.ServerConfig",
> {
>        statics :
>        {                          
>              getServiceUrl : function()
>              {
> if (qx.core.Variant.isSet("qx.debug", "on"))  {
>     return "http://localhost/web/.qxrpc?instanceId=server.debug";
> }
> else {
>     return qx.io.remote.Rpc.makeServerURL();        
> }
>              }
>        }
>        
> });
>
> It returns null for my.ServerConfig.getServiceUrl() when I use
> this.getRpcUrl(). Is it because of the static initializer in init method?
> Can't we call Static methods in init?
>  
The generator has problems with code like this because you are calling a
static method during class define. This creates a load time dependency
between my.ServerConfig and my.Gui, which means my.ServerConfig must be
included before my.Gui. This kind of dependency is hard to detect and
the generator sometimes fails to detect it. You can however tell the
generator manually about this dependency by adding this line in the head
of the my.Gui class:

/*
#require(my.ServerConfig)
*/


Best Fabian

--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG
Brauerstraße 48
76135 Karlsruhe

Amtsgericht Montabaur HRB 6484

Vorstand: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Matthias Greve, Robert Hoffmann, Markus Huhn, Oliver Mauss, Achim Weiss
Aufsichtsratsvorsitzender: Michael Scheeren


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Static method in property init

kanugula

Thanks for your reply.

I tried the following, but still didn't work. The source/build version gives
a warning saying  'require(my.ServerConfig) is auto-detected'.

Anyway, this is a minor issue. I re-arranged my code and removed static
initializer.

Thanks.
Kanugula.

/*
#require(my.ServerConfig)
*/

Fabian Jakobs-2 wrote:

>
> Hi Kanugula,
>> Hi,
>>
>> Why is this not working?
>>
>> qx.Class.define("myGui",
>> {
>>     extend : myAbstractGui,
>>
>>     properties :
>>     {
>>  rpcUrl :
>>  {
>>    init :
>> my.ServerConfig.getServiceUrl()+"?request=delete&system=mySystem",
>>  nullable : false
>>  }
>>    },
>>
>> }
>>
>> qx.Class.define("my.ServerConfig",
>> {
>>        statics :
>>        {                          
>>              getServiceUrl : function()
>>              {
>> if (qx.core.Variant.isSet("qx.debug", "on"))  {
>>     return "http://localhost/web/.qxrpc?instanceId=server.debug";
>> }
>> else {
>>     return qx.io.remote.Rpc.makeServerURL();        
>> }
>>              }
>>        }
>>        
>> });
>>
>> It returns null for my.ServerConfig.getServiceUrl() when I use
>> this.getRpcUrl(). Is it because of the static initializer in init method?
>> Can't we call Static methods in init?
>>  
> The generator has problems with code like this because you are calling a
> static method during class define. This creates a load time dependency
> between my.ServerConfig and my.Gui, which means my.ServerConfig must be
> included before my.Gui. This kind of dependency is hard to detect and
> the generator sometimes fails to detect it. You can however tell the
> generator manually about this dependency by adding this line in the head
> of the my.Gui class:
>
> /*
> #require(my.ServerConfig)
> */
>
>
> Best Fabian
>
> --
> Fabian Jakobs
> JavaScript Framework Developer
>
> 1&1 Internet AG
> Brauerstraße 48
> 76135 Karlsruhe
>
> Amtsgericht Montabaur HRB 6484
>
> Vorstand: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas
> Gottschlich, Matthias Greve, Robert Hoffmann, Markus Huhn, Oliver Mauss,
> Achim Weiss
> Aufsichtsratsvorsitzender: Michael Scheeren
>
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
View this message in context: http://www.nabble.com/Static-method-in-property-init-tp17874121p17957266.html
Sent from the qooxdoo-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Static method in property init

Fabian Jakobs
Administrator
kanugula schrieb:

> Thanks for your reply.
>
> I tried the following, but still didn't work. The source/build version gives
> a warning saying  'require(my.ServerConfig) is auto-detected'.
>
> Anyway, this is a minor issue. I re-arranged my code and removed static
> initializer.
>
> Thanks.
> Kanugula.
>
> /*
> #require(my.ServerConfig)
> */
>
> Fabian Jakobs-2 wrote:
>  
>> Hi Kanugula,
>>    
>>> Hi,
>>>
>>> Why is this not working?
>>>
>>> qx.Class.define("myGui",
>>> {
>>>     extend : myAbstractGui,
>>>
>>>     properties :
>>>     {
>>>  rpcUrl :
>>>  {
>>>    init :
>>> my.ServerConfig.getServiceUrl()+"?request=delete&system=mySystem",
>>>  nullable : false
>>>  }
>>>    },
>>>
>>> }
>>>
>>> qx.Class.define("my.ServerConfig",
>>> {
>>>        statics :
>>>        {                          
>>>              getServiceUrl : function()
>>>              {
>>> if (qx.core.Variant.isSet("qx.debug", "on"))  {
>>>     return "http://localhost/web/.qxrpc?instanceId=server.debug";
>>> }
>>> else {
>>>     return qx.io.remote.Rpc.makeServerURL();        
>>> }
>>>              }
>>>        }
>>>        
>>> });
>>>      

BTW you can rewrite you method to be a bit faster:

getServiceUrl : qx.core.Variant.select("qx.debug",
{
  "on" : function() { return "http://localhost/web/.qxrpc?instanceId=server.debug"; },
  "off" : function() { return qx.io.remote.Rpc.makeServerURL(); }
}),


This way the variant is only checked at class define time and not each
time the method is called.

Best Fabian

--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG
Brauerstraße 48
76135 Karlsruhe

Amtsgericht Montabaur HRB 6484

Vorstand: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Matthias Greve, Robert Hoffmann, Markus Huhn, Oliver Mauss, Achim Weiss
Aufsichtsratsvorsitzender: Michael Scheeren


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Loading...