[ 3 posts ]

Jakub Kuźma

YUI Contributor

  • Username: qoobaa
  • Joined: Mon Jul 06, 2009 2:29 pm
  • Posts: 8
  • GitHub: qoobaa
  • Gists: qoobaa
  • Offline
  • Profile

Extend and widgets

Post Posted: Mon Jul 06, 2009 2:49 pm
+-1-
Hi everybody!

I've just started to learn YUI3, and I think I'll have a lot of questions about it. I'm trying to create hierarchy of widgets like: Exchange < Resources < Widget. Because Exchange widget is slightly different than Resources widget, I need to override e.g. renderUI method to add some additional stuff there. The question is: how can I call renderUI method from base (Resources) class? After a lot of different approaches I've found the bind method working:
Code:
renderUI: function() {
  Y.bind(Resources.superclass.renderUI, this)();
}

Is there any easier way to do it?

Another qustion: can I create widgets inside of other widgets? I know it's possible, but does it make any sense? Maybe there's a better way to do it?

I'm trying to make a game based on The Settlers of Catan board game. The code is available on Github: http://github.com/qoobaa/pioneers/tree/yui. ANY help is appreciated, I'd be perfect to hear a criticism or some hints :-).

Satyen Desai

YUI Developer

  • Username: sdesai
  • Joined: Tue Dec 09, 2008 4:17 pm
  • Posts: 302
  • GitHub: sdesai
  • Gists: sdesai
  • YUI Developer
  • Offline
  • Profile

Re: Extend and widgets

Post Posted: Mon Jul 06, 2009 3:16 pm
+0-
If I'm following you correctly (Exchange extends Resource extends Widget), you can just do this:

Code:

Exchange.prototype.renderUI = function() {
    // Call Resource's renderUI from Exchange
    return Exchange.superclass.renderUI.apply(this, arguments);
}

or,

Resource.prototype.renderUI = function() {
    // Call Widget's renderUI from Resource
    return Resource.superclass.renderUI.apply(this, arguments);
}


Yes, you can nest Widgets, however we don't have the parent/child relationship formalized yet. Look for that to take shape in the 3.1 release.

Joh

  • Username: snilsor
  • Joined: Fri Jul 10, 2009 2:22 am
  • Posts: 14
  • Offline
  • Profile

Re: Extend and widgets

Post Posted: Mon Jul 20, 2009 6:37 am
+0-
sdesai wrote:
Code:

Exchange.prototype.renderUI = function() {
    // Call Resource's renderUI from Exchange
    return Exchange.superclass.renderUI.apply(this, arguments);
}




I want to mention for your own troubleshooting that .apply(..) gives me in my class hierarchies a silent die on calling my superclass constructors (and methods).
I only get this working with
Code:
superclass.constructor.call(this, args);


Regards
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
cron