1. #1
    Sencha User
    Join Date
    Jan 2008
    Location
    Mumbai
    Posts
    27
    Vote Rating
    0
    sjmittal is on a distinguished road

      0  

    Default Unanswered: When to call a mixin constructor

    Unanswered: When to call a mixin constructor


    Hi,
    I was designing custom class for my application and needed to have some better understanding of mixins.

    Let me explain by taking existing class Ext.AbstractComponent.
    It has following mixins:
    Code:
    Ext.define('Ext.AbstractComponent', {
        mixins: {
            positionable:  Ext.util.Positionable ,
            observable:  Ext.util.Observable ,
            animate:  Ext.util.Animate ,
            elementCt:  Ext.util.ElementContainer ,
            renderable:  Ext.util.Renderable ,
            state:  Ext.state.Stateful 
        },
        ....
    }, ...);
    Now in the constructor of this class some mixins is initialized like this (by calling their constructors):
    Code:
    constructor : function(config) {
        ...
        me.initialConfig = config;
        me.mixins.elementCt.constructor.call(me);
        me.addEvents(...);
        ...
        me.initComponent();
        ...
        me.mixins.observable.constructor.call(me);
        me.mixins.state.constructor.call(me, config);
        ...
    }
    However I see that mixin renderable constructor is never called.

    So my basic question is how to we decide if are to call the constructor of mixin or not. I believe here calling the constructor just executes some initialization code and not create an instance of mixin as the properties are mixin are already mixed into main class.

    Any light on this will help me and maybe others to figure out how to best use mixins.

    Thanks
    Sachin

  2. #2
    Sencha User
    Join Date
    May 2012
    Location
    Blumenau - Brazil
    Posts
    50
    Vote Rating
    8
    Answers
    12
    julio.batista will become famous soon enough

      0  

    Default


    It should be called in your class' constructor. As you said, it will only execute some initialization code, so you can call it when you think it should be called. As it's a constructor, makes more sense calling it inside the class' constructor.
    --
    Júlio César Batista - blog - twitter
    Web Developer

Thread Participants: 1

Tags for this Thread