-
14 Jul 2011 12:20 AM #1
New model define's callback does not have access to this.proxy
New model define's callback does not have access to this.proxy
Hello, I posted this in the generic forum but got unreplied, I'm more convinced that this may be a bug, thus I am reposting in Bugs.
This code produces "undefined", as if the class attribute "proxy" has not yet been defined. However, calling Foo.proxy afterwise retrieves the correct proxy instance.Code:Ext.define('Foo', { extend: 'Ext.data.Model', proxy: { type: 'rest', url: '/aaa' } }, function() { console.log(this.proxy); });
Looking deeper in the source I notice that in Ext.data.Model's onClassExtended:
setProxy is called *after* onBeforeClassCreated (which in turn calls the onClassCreated callback) thus calling the final callback before the model is properly initialized.Code:onBeforeClassCreated.call(me, cls, data); cls.setProxy(cls.prototype.proxy || cls.prototype.defaultProxyType);
In my application I have to dynamically define models and operate on them only after they have been initialized so this behavior would be problematic.
I made this patch that overrides the onClassCreated in order to move setProxy() after the class is instantiated but before the final callbacks are called. It seems to work but I don't know if it is the proper approach, please give it a look:
Code:--- /home/yggdra/ext-4.0.2a/src/data/Model.js 2011-06-15 01:23:25.000000000 +0200 +++ public/ext/src/data/Model.js 2011-06-29 04:24:30.330159437 +0200 @@ -378,12 +378,19 @@ onBeforeClassCreated.call(me, cls, data); - cls.setProxy(cls.prototype.proxy || cls.prototype.defaultProxyType); - // Fire the onModelDefined template method on ModelManager Ext.ModelManager.onModelDefined(cls); }); }; + + var onClassCreated = data.onClassCreated; + + data.onClassCreated = function(cls, data) { + var me = this; + cls.setProxy(cls.prototype.proxy || cls.prototype.defaultProxyType); + + onClassCreated.call(me, cls, data); + }; }, inheritableStatics: {
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote