1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,406
    Vote Rating
    176
    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 Ext.util.Observable usage

    Ext.util.Observable usage


    I did a search of the entire Ext JS code base to see how the Ext.util.Observable class is used...

    The mixin pattern is used the most frequently, but a small number of Ext JS classes extend Observable.

    Is there a reason for this inconsistency? I think the mixin pattern should be preferred because it makes the prototype chain shorter.

    Code:
    Ext.define('Ext.state.Provider', {
        mixins: {
            observable: 'Ext.util.Observable'
        },
        ...
    Code:
    Ext.define('Ext.selection.Model', {
        extend: 'Ext.util.Observable',
        alternateClassName: 'Ext.AbstractSelectionModel',
        requires: ['Ext.data.StoreManager'],
        mixins: {
            bindable: 'Ext.util.Bindable'    
        },
        ....

  2. #2
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    418
    Vote Rating
    61
    burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough burnnat is a jewel in the rough

      0  

    Default


    I can't speak authoritatively (of course), but if I were to offer a guess, my first impression is that it could be because Ext.util.Observable provides a constructor that is automatically inherited by subclasses, but has to be explicitly called when used as a mixin. As a result, strict subclasses have somewhat cleaner code:
    Code:
    Ext.define('MixinObservable', {
        mixins: {
            observable: 'Ext.util.Observable'
        },
        
        constructor: function() {
            var me = this;
            me.mixins.observable.constructor.call(me);
        }
    })
    
    // ... versus ...
    
    Ext.define('SubclassObservable', {
        extend: 'Ext.util.Observable'
    });
    Whether the shorter prototype chain is worth the tradeoff with more verbose code is a separate question, I think. And this is just a guess anyway.

Thread Participants: 1