PDA

View Full Version : Inheritance allowed in mixins?



burnnat
30 Nov 2011, 9:55 AM
I ran across this situation, but I'm not sure if it's expected behavior or a bug. I wanted to create a sub-mixin that would inherit some methods from a parent:


Ext.define('BaseMixin', {
doBasicStuff: function() {
console.log('some basic stuff');
}
});

Ext.define('ExtendedMixin', {
extend: 'BaseMixin',

doExtendedStuff: function() {
console.log('some additional stuff');
this.doBasicStuff();
}
});

Ext.define('MyClass', {
mixins: {
extended: 'ExtendedMixin'
},

doAllStuff: function() {
console.log('some class-specific stuff');
this.doExtendedStuff();
}
})

Ext.onReady(function() {
Ext.create('MyClass').doAllStuff();
});

This, however, gives an error that "this.doBasicStuff is not a function". I can add the following in ExtendedMixin as a workaround:

doBasicStuff: function() {
this.callParent();
}

But that seems kind of silly, not to mention tedious if there are multiple inherited methods. So what's the verdict? Should you be allowed to extend mixins, or is this an abuse of the class system?

mitchellsimoens
30 Nov 2011, 10:54 AM
If it extends Ext.Base (or a subclass) then it should be able to be extended. If you are using Ext.define, you are extending Ext.Base (or a subclass).

burnnat
30 Nov 2011, 10:57 AM
So then this is a bug? In my example, only the direct members of the mixin class get mixed into the target class, not any of the members inherited from the parent.

ykey
7 Mar 2012, 11:54 AM
Anything ever decided on this one? Seeing same problem.

börn
7 Mar 2012, 11:03 PM
yap funny one... i solved this by mixing the Mixin into my Mixin ;) ...:



Ext.define('ExtendedMixin', {
mixins: {baseMixin: 'BaseMixin'},

doExtendedStuff: function() {
console.log('some additional stuff');
this.doBasicStuff();
}
});


not really what one want... but it works finally for me (you can't use callParent then of course).

LesJ
8 Mar 2012, 7:46 AM
I tried your example and it works in 4.1 B2 and B3. I see the same error in 4.0.7.

burnnat
8 Mar 2012, 7:49 AM
Sorry for not chiming in sooner, but yes - @LesJ is right. Happily, this appears to have been fixed in 4.1. :)

börn
9 Mar 2012, 1:42 AM
great news! ;)