1. #1
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default 4.1 RC3: store load callback not firing

    4.1 RC3: store load callback not firing


    I'm loading stuff from multiple stores like this:

    Code:
    for (var i in stores) {
      var store = stores[i];
    
      store.load({
        scope:    { store: store, params: myExtraParams },
        callback: myCallback
      });
    }
    where myCallback is a function which should be fired for each store loaded with the context given. On 4.0 it works, but testing with 4.1 RC3 it does not.

    If I just try to output something on the console like this:

    Code:
    function myCallback(records, operation, success) {
      console.log('myCallback is being called');
    }
    This gives nothing in the web console on 4.1 RC3. On 4.0 it does.

    I can see in the Chromium Network tab that the data is being loaded with a 200 OK, and JSON as payload.

    Is this a bug, or an intended change? How should I set up the callbacks?

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    This is not recommended. There is no method to detect which response is coming back in what order and you are most likely having collisions with your incoming data regards if it is successful or not.

    Look at it as throwing a hundred pennies up on the air and hoping they come back down in the same order.

    I would setup an exception handler on loading all your store, then use the callback for individual loading.

    Regards.
    Scott.

  3. #3
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    This is not recommended. There is no method to detect which response is coming back in what order and you are most likely having collisions with your incoming data regards if it is successful or not.

    Look at it as throwing a hundred pennies up on the air and hoping they come back down in the same order.
    In myCallback I wait for all the stores to be loaded successfully before proceeding to present the information to the user. The order does not matter, and it is faster than doing it in a serial manner.

    Quote Originally Posted by scottmartin View Post
    I would setup an exception handler on loading all your store, then use the callback for individual loading.
    How would I go about doing this? Can you point me to some more information?

    Anyway, I still think it is a problem that it does not fire the callback like it used to. That will probably break a lot of code - at least of mine.

    Edit: you would have to remove the callback parameter from the API:

    http://docs.sencha.com/ext-js/4-0/#!...re-method-load

    I also tried giving a plain callback function to the load method, with similar results:

    Code:
    store.load(myCallback);
    Not firing.

  4. #4
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,119
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Im really amazed about that scope definition, I have never seen it this way

    Code:
    store.load({
        scope:    { store: store, params: myExtraParams },
        callback: myCallback
      });
    Isn't it?

    Code:
    store.load({
        scope:    store,
        params: myExtraParams,
        callback: myCallback
      });

  5. #5
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Quote Originally Posted by tvanzoelen View Post
    Im really amazed about that scope definition, I have never seen it this way

    Code:
    store.load({
        scope:    { store: store, params: myExtraParams },
        callback: myCallback
      });
    Well, you can pass basicly anything as the scope. Here it is an object with two members. You can then refer to "this.myExtraParams" in the callback.

    That version with the 'params' attribute isn't actually even described in the API proper (just in someone's comment).

    But the callback does not fire in 4.1 all the same. I've tried it completely without any scope definition whatsoever, giving load() just the callback function as the only parameter.

  6. #6
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,119
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    The scope must be defined and in that scope the function myCallback must exist.

    Maybe first try to set the funciton directly on the callback, if that works the function is out of scope probably

  7. #7
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Quote Originally Posted by tvanzoelen View Post
    The scope must be defined and in that scope the function myCallback must exist.

    Maybe first try to set the funciton directly on the callback, if that works the function is out of scope probably
    Now it looks like this:

    Code:
          store.load( function () { console.log("load fired"); } );
    But still doesn't print anything in the console log...

  8. #8
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,119
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Don't forget to set the callback and its parameters,

    Code:
     store.load({ callback: function (records, operation, success) { console.log("load fired"); } });

  9. #9
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    Actually by trial and error I just discovered that commenting out an earlier call to store.filter() makes the callback fire.

    I am filtering all the stores using some criterion. Here's a more complete example. Sorry for not including it in the first place:

    Code:
    for (var i in stores) {
      var store = stores[i];
    
      // Clear all previous filters
      store.filters.clear();
    
      // Filter and load new data [ commenting this out makes the callback fire: ]
      store.filter({
        property: storedFormManager.filterProperty,
        value:        storedFormManager.filterId
      });
    
      store.load({
        scope:    {
          store: store, 
          manager: storedFormManager
        },
        callback: storeLoaded
      });
    }
    
    // Callback
    function storeLoaded(records, operation, success) {
      var store = this.store,
          manager = this.manager;
    
      // Fire dataloaded event for the store
      manager.fireEvent('dataloaded', manager, store);
    
      // Check if all stores in the manager have been loaded successfully
      var allLoaded = true;
    
      for (var i in manager.stores) {
        if (manager.stores[i].managerProps.loaded == false) allLoaded = false;
      }
    
      // Also check if submanagers have been fully loaded
      for (var i in manager.submanagers) {
        if (manager.submanagers[i].loaded == false) allLoaded = false;
      }
    
      if (allLoaded) {
        manager.fireEvent('alldataloaded', manager);
      }
    }
    Commenting out that store.filter(...) call makes the callback fire. Though then it will not work correctly because I have non-filtered data...

  10. #10
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,119
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    I filter my data in the callback of a load. Why filter data if the store isn't loaded yet?