True enough. Not all base classes are bad ... just some of them :)
Printable View
Hi all,
Well, after testing some cases, I'm really not liking this new behavior in Ext.override('...', {...});, maybe I'm still missing something,
For example, in 4.1, I have a few overrides like this one:
but when Ext.layout.Context.runLayout runs, it calls layout.calculate(ownerContext), and, for a fit layout, the original calculate function is called instead of the override and thus it's giving me:Code:Ext.override('Ext.layout.container.Fit', {
calculate: function (ownerContext) {
var me = this,
childItems = ownerContext.childItems,
/* begin workaround */
//length = childItems.length,
length = childItems !== undefined ? childItems.length : 0,
/* end workaround */
targetSize = me.getContainerSize(ownerContext),
contentSize = { width: 0, height: 0 },
i;
for (i = 0; i < length; ++i) {
me.fitItem(ownerContext, childItems[i], targetSize, contentSize);
}
if (!ownerContext.setContentSize(contentSize.width, contentSize.height)) {
me.done = false;
}
}
});
"Uncaught TypeError: Cannot read property 'length' of undefined"... (This error happens when there is a panel without child items, just using the html: property, I can report it in another post if it helps)
I understand and see the value of being able to have partial definitions of classes (coming from a .net world where partial classes are used somewhat widely), but maybe using another name instead of override, and let override do what the name suggest...
Thanks again
Yep, I know that workaround should not be needed, but I'm doing those overrides so I can test the 4.1.
I've used a few overrides for fixing problems that I got in 3.x, then in 4.0 and for sure, somewhere in the future I'd need some overrides to fix bugs until they are fixed in new releases (hopefully we'll be getting access to the 4.1 svn/git branch soon), so I need to find a reliable way to override some methods in ExtJS >= 4.1.
I've tried modifying directly ext-all-dev and they let me use my app with a few quirks here and there, but no errors, and I'm very pleased with the performance improvements, but obviously this method shouldn't be used....
I've tried doing the old school "Ext.layout.container.Fit.prototype.calculate = function (ownerContext) { ... };" for all my overrides, and although no error is raised, the app is not rendering as it is if I do the changes directly in ext-all-dev.... gotta investigate more why.
So, that's why I'm raising this issue about Ext.override(''..", {..}); these kind of overrides worked on 3.x and 4.0, so, I'm trying to find a way to be able to override core methods reliably.
Hello Don, thanks for your response,
Yup, in my tests, the override doesn't seems to be called, so that's the part I'm not liking (as I'm guessing more changes where done to that behavior, but maybe I'm wrong - I've not checked the core code to verify it -), I've no problem with the callParent change...
My override isn't getting called (tried some console.log) when the runLayout calls layout.calculate(....) as it calls the overridden original method...
The form you have should work in both 4.0 and 4.1, give or take using the string class name. You could try removing the quotes on the class name you are overriding.
You could try (in 4.1 only):
With appropriate namespaces and pathing of course. :)PHP Code:Ext.define('My.patch.Fit', {
override: 'Ext.layout.container.Fit',
calculate: function () {
...
}
});
//--- in your app:
{
layout: 'fit',
requires: 'My.patch.Fit'
}
This is a big part of why Ext.define/override was added in 4.1: to help manage overrides and when they are included in a build and when they can be (safely) applied to their target class.
Hope this helps!