Hybrid View

  1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,389
    Vote Rating
    170
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default What is xhooks?

    What is xhooks?


    Is this a private or a public feature? Can I use it in my custom widgets?

    The panel Header is the only place where xhooks is used in Ext.

    Code:
    Ext.define('Ext.panel.Header', {
        ....
        initComponent: function() {
            ...
                me.titleCmp = new Ext.draw.Component({
                    width     : 15,
                    ariaRole  : 'heading',
                    focusable : false,
                    viewBox   : false,
                    flex      : 1,
                    id        : me.id + '_hd',
                    autoSize  : true,
                    margins   : '5 0 0 0',
                    items     : [ me.textConfig ],
                    xhooks: {
                        setSize: function (width) {
                            // don't pass 2nd arg (height) on to setSize or we break 'flex:1'
                            this.callParent([width]);
                        }
                    },
                    // this is a bit of a cheat: we are not selecting an element of titleCmp
                    // but rather of titleCmp.items[0]
                    childEls  : [
                        { name: 'textEl', select: '.' + me.baseCls + '-text' }
                    ]
                });
            ....            
        },
        ...

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,524
    Vote Rating
    873
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    I found Ext.AbstractComponent#constructor is where xhooks is used:

    Code:
        constructor : function(config) {
            var me = this,
                i, len, xhooks;
    
            if (config) {
                Ext.apply(me, config);
    
                xhooks = me.xhooks;
                if (xhooks) {
                    me.hookMethods(xhooks);
                    delete me.xhooks;
                }
            } else {
                config = {};
            }
    
    .....
    hookMethods is on Ext.Base which iterates through the hooks object and executes hookMethod on each:

    Code:
            hookMethod: function (name, hookFn) {
                var me = this,
                    owner = me.self;
    
                //<debug>
                var className = owner.$className;
                if (className) {
                    hookFn.displayName = className + '#' + name;
                }
                //</debug>
    
                hookFn.$owner = owner;
                hookFn.$name = name;
    
                if (me.hasOwnProperty(name)) {
                    hookFn.$previous = me[name]; // already hooked, so call previous hook
                } else {
                    hookFn.$previous = callHookParent; // special "previous" to call on prototype
                }
    
                me[name] = hookFn;
            },
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,389
    Vote Rating
    170
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default


    When I worked with Dojo, they had the ability to run code before and after the class constructor, so this looks to me like a place to run preamble code.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,524
    Vote Rating
    873
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Didn't look more at the constructor of AbstractComponent but the code snippets I posted doesn't look like the hook method is being fired, just placed onto the instance.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,389
    Vote Rating
    170
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Didn't look more at the constructor of AbstractComponent but the code snippets I posted doesn't look like the hook method is being fired, just placed onto the instance.
    This a very good point... that xhooks is mixed into the instance.

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,524
    Vote Rating
    873
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    For an app I use I actually added 4 events that have helped me personally... I fire an event in the start of constructor and initComponent and an event at the end of the constructor and initComponent. This allow a great deal of logic to happen in the Controller for me like the view had no clue what children it should have as that logic was moved into the Controller. This was done with a simple override but IE probably doesn't like it
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.