Hybrid View

  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2007
    Posts
    61
    Vote Rating
    0
    Shyru is on a distinguished road

      0  

    Question 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:
    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]);
    			}
    		}
    	})
    });
    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.
    If needed I would be willing to provide a complete testcase.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,629
    Vote Rating
    435
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  3. #3
    Ext JS Premium Member
    Join Date
    Dec 2007
    Posts
    61
    Vote Rating
    0
    Shyru is on a distinguished road

      0  

    Default


    Yes, all methods are there. I just tried again with 4.1-Beta2. Should I report a Bug?

  4. #4
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    205
    Vote Rating
    4
    christophe.geiser will become famous soon enough

      0  

    Default


    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:

    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
    
    
    })
    Fix : we should have a proper closure in base.borrow, or use Ext.Function.clone as in 4.1 :
    Code:
      if (typeof toBorrow == 'function') {
                        fn = function(b) {
                            return function() {b.apply(this, arguments)};
                        }(toBorrow);
    C.

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    15,087
    Vote Rating
    97
    evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold

      0  

    Default


    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 c2
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  6. #6
    Sencha User
    Join Date
    Nov 2008
    Location
    Lyon, France
    Posts
    205
    Vote Rating
    4
    christophe.geiser will become famous soon enough

      0  

    Default


    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.