Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Maintaining Component References

  1. #1
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default Maintaining Component References

    Well, this is not really an extension or a plugin, just a bit of code to make life more easier in large ExtJs applications.

    I have always found referring to ExtJs components a hassle, especially in deeply nested layouts. The combination of id, itemId, and ref has not given me the flexibility I wanted.

    So, I created a new way of maintaining Component references, that I have discussed here:
    http://www.rahulsingla.com/blog/2010...ations-part-ii

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Page won't load.

  3. #3
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Looks like the server is sluggish currently. Let me check. I will update when the server is back to normal.

  4. #4
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Hi Animal, I believe the server is responding a lot better now.

  5. #5
    Sencha User
    Join Date
    Feb 2008
    Location
    USA
    Posts
    162

    Default

    This is fantastic! I've been doing this another, and I've been wanting to hook into Ext to be a bit more efficient about it.

    Thanks for the concept!!

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    OK, except there's no reason to introduce yet another ID configuration.

    itemId is already there to provide a scoped identifier. And if not specified, it defaults to the ID.

    So your code could be

    Code:
    Ext.Component.prototype.initComponent = Ext.Component.prototype.initComponent.createSequence(function() {
        var iid = this.getItemId();
        if (this.ns && iid) {
          if (Ext.isFunction(this.ns.reg)) {
            this.ns.reg(iid, this);
          } else {
            this.ns[iid] = this;
          }
        }
    });
    Then

    Code:
    var ns=Rahul.Ext.allocateControlNamespace();
    var pn = new Ext.Panel({
        title: 'Login',
        layout: 'form',
        listeners: { show: pnlLoginShown },
        ns: ns,
        itemId: 'pnlLogin',
        items: [{ xtype: 'textfield', fieldLabel: 'Username', ns: ns, itemId: 'txtUsername', listeners: {specialkey:txtLoginSpecialKey} },
        { xtype: 'textfield', fieldLabel: 'password', ns: ns, itemId: 'txtPassword', listeners: { specialkey: txtLoginSpecialKey} }
        ]
    });
    But have you seen SamuraiJack's "slots" concept. It's similar but simpler.

  7. #7
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Hmm.. well yes, I should have considered this. Probably, re-using itemId instead of introducing nsName could have been better. But apart from these minor implementation details, overall, this has simplified how I manage references to a large number of components significantly.

  8. #8
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    If I recall correctly (I have been using variations of this approach for over a year now, before finally settling on this one), probably one reason why I chose nsName over itemId was better debugging.

    As you said Animal, itemId defaults to id if not specified. That means, if I use itemId, every component gets registered to the namespace ns, either with an explicit id, or an auto-generated one (on the lines of ext-genxxxx).

    This made it difficult for me while debugging in FireBug & in various IDEs when I set a watch on the namespace and tried to inspect various Components, and those which I did not wish to get registered (lots of labels, layout containers etc, which are always static and I really did not need to access them in code), also showed up, making it difficult to browse through the actual references I was interested in.

  9. #9
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Yes, that is true, all Components will get registered to a namespace if you configure them with the ns config.

  10. #10
    Sencha Premium User
    Join Date
    Mar 2009
    Posts
    254

    Default

    Well, I did not want that, and therefore used nsName. If someone doesn't mind getting all components registered, then probably itemId is a better option. In any case, any of these 2 should be lot better and maintainable than refs & stand-alone itemIds (without ns).

Page 1 of 2 12 LastLast

Similar Threads

  1. Keeping references in component getters
    By IHaveRead in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 31 Jan 2010, 12:35 AM
  2. [SOLVED] Extending classes and maintaining references
    By ZachG in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 20 Jan 2010, 8:42 PM
  3. maintaining scroll position
    By repata in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 24 Oct 2008, 9:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •