-
17 Jan 2012 7:07 AM #1
Ext.base.borrow not working as with ExtJs 4.0.7?
Ext.base.borrow not working as with ExtJs 4.0.7?
We have an override for Ext.data.AbstractStore that adds plugin-support for Stores. To minimize needed changes between ExtJS updates I coded it with using borrow which borrows the plugin initialization logic from Ext.AbstractComponent like this:
In ExtJs 4.0.7 this was working fine, but with ExtJS 4.1Beta1 this bails out in constructPlugin() where plugin is null. I tried to debug it, but debugging borrowed methods is kinda fun. Perhaps its a scope problem. I noticed that Ext.Base.borrow changed a lot between 4.0.7 and 4.1Beta1. So either this introduced a bug or I'm doing something wrong.Code:/* * Add plugin support for stores. * This is done by borrowing some methods from Ext.AbstractComponent and modifying the constructor of Ext.data.AbstractStore */ //borrow plugin methods from AbstractComponent Ext.data.AbstractStore.borrow(Ext.AbstractComponent,['plugins','constructPlugins','getPlugin','initPlugin','constructPlugin']); //add plugin initialisation code at the end of the constructor of Ext.data.AbstractStore: Ext.override(Ext.data.AbstractStore,{ constructor:Ext.Function.createSequence(Ext.data.AbstractStore.prototype.constructor,function(){ var i,len; if (this.plugins) { console.log("Plugins are:",this.plugins); this.plugins = [].concat(this.plugins); this.constructPlugins(); for (i = 0, len = this.plugins.length; i < len; i++) { this.plugins[i] = this.initPlugin(this.plugins[i]); } } }) });
If needed I would be willing to provide a complete testcase.
-
17 Jan 2012 8:14 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 434
So if you look at the prototype of Ext.data.AbstractStore, are the methods there?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
30 Jan 2012 7:27 AM #3
Yes, all methods are there. I just tried again with 4.1-Beta2. Should I report a Bug?
-
2 Jan 2013 1:26 PM #4
Yes, this is definitively a bug - and potentially a serious one if your app use borrowing methods. Only the last member will be applied/borrowed:
Fix : we should have a proper closure in base.borrow, or use Ext.Function.clone as in 4.1 :Code:Ext.onReady(function(){ Ext.define('C1', { name : 'c1', f1: function(){ console.info('f1', this.name) this.f2() }, f2: function(){ console.info('f2', this.name) } }) Ext.define('C2', { name : 'c2' }, function() {this.borrow(C1,['f1', 'f2'])}) c1 = new C1(); c2 = new C2() c1.f1(); c2.f1(); // only call f2 })
C.Code:if (typeof toBorrow == 'function') { fn = function(b) { return function() {b.apply(this, arguments)}; }(toBorrow);
-
2 Jan 2013 3:09 PM #5
Are you saying there is a problem with the 4.2 beta? When I run the example code I see:
f1 c1
f2 c1
f1 c2
f2 c2Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
2 Jan 2013 11:50 PM #6
Thanks for the answer, and oups...
Downloaded what I thought to be the latest version from "ExtJS 4.1 beta 2 is available", first post in "ExtJs 4.2.0" Forum !
Base.borrow looks fine in 4.2.0. Cant believe I tried to fix a 4.1 bug...
Cheers
C.


Reply With Quote