Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Promises and Deferreds/Futures in Ext JS?

  1. #11
    Ext Premium Member Jan (HL)'s Avatar
    Join Date
    Aug 2010
    Location
    Germany
    Posts
    111
    Vote Rating
    9
      2  

    Default

    Quote Originally Posted by Animal View Post
    All those pages seem quite opaque in what actually happens.

    Can you post some possible example of what you would like to happen?
    PHP Code:
    // Proposal
    var gridStoredetailsStoretreegridform;
    tree.on('click', function(treerecord){
      var 
    promise gridStore.load({id record.get('id')});
      
    promise.success(detailsStore.load).success(form.update).failure(form.showError);
    });

    // instead of something like this.
    tree.on('click', function(treerecord){
      
    gridStore.load({
        
    id record.get('id'), 
        
    callback : function(rosuccess){
          if (
    success) {
            
    detailsStore.load({
              
    callback:function(rosuccess){
                if (
    success) {
                  
    form.update(record);
                } else {
                  
    form.showError();
                }
              }
            });
          } else {
            
    form.showError();
          }
        }
      });
    }); 
    It's not just callbacks. It is a different way of dispatching events. The real problem I see is the challenge of Sencha to provide an api which *is* deferable. Without chaining support (like jQuery) it is useless.

    Again, an example of jQuery promise implementation:
    PHP Code:
    var ajaxPromise = $.ajax('myurl').done(function(response){
      
    console.info("the response: " response);
    }).
    fail(function(){
      
    console.warn(arguments);
    });
    // oops, I need additional callbacks?
    ajaxPromise.done(function(){
      
    console.info('done!!');
    }).
    always(function(){
      
    console.log("whatever happend, I'm here");
    }); 
    Mod: Sencha frameworks have chaining support, just override the methods you want chainable.

  2. #12
    Sencha User
    Join Date
    Sep 2010
    Posts
    5
    Vote Rating
    1
      0  

    Default jQuery has this

    One of the main uses for this feature is to save coders from callback spaghetti hell. Instead of deeply nested success/failure callback code you describe a series of operations as objects and then compose them. The jQuery implementation is pretty nice and is covered in detail here: http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks-with-jquery-promises/

    E
    xtJS is nearly always ahead of the curve in terms of good design practices, so I'm surprised not to see something like this in there yet.

  3. #13
    Sencha User
    Join Date
    Sep 2011
    Posts
    1
    Vote Rating
    4
      4  

    Default

    the fact that sencha is completely clueless about promises/futures and think they're just callbacks is absolutely disconcerting to me.

  4. #14
    Sencha Premium Member
    Join Date
    Jun 2012
    Location
    Auckland, New Zealand
    Posts
    6
    Vote Rating
    2
      1  

    Default

    It's worth noting that jQuery's implementation isn't a 100% faithful implementation of Promises - see You're Missing the Point of Promises for more.

  5. #15
    Sencha User
    Join Date
    May 2011
    Location
    Melbourne, Australia
    Posts
    89
    Vote Rating
    7
      1  

    Default

    I know this is a little late, but for reference.
    A great article by Matt Goldspink "Promises in Ext.js and Sencha Touch":
    http://www.mattgoldspink.co.uk/2013/...-sencha-touch/

  6. #16
    Sencha Premium User
    Join Date
    Feb 2012
    Location
    Berne, Switzerland
    Posts
    723
    Vote Rating
    46
      0  

    Default

    It looks like there is an implementation of Promises in ST2.3.1.
    You can find it in touch\src\promise.js

  7. #17
    Sencha User
    Join Date
    Nov 2011
    Posts
    21
    Vote Rating
    5
      0  

    Default

    DeftJS is quite nice for this. Also their ViewController implementation is quite nice. Their promises make things quite a bit less nested when dealing with asnychronous code.

    www.deftjs.org

  8. #18
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    262
    Vote Rating
    79
      0  

    Default

    Quote Originally Posted by Greg Arnott View Post
    I know this is a little late, but for reference.
    A great article by Matt Goldspink "Promises in Ext.js and Sencha Touch":
    http://www.mattgoldspink.co.uk/2013/...-sencha-touch/
    Nice article
    Why Sencha can't adopt solution that already is out there: rvsp.js, when.js, deft.js or many others.
    Deft is already ExtJS specific, so plugging this into core won't be so hard.

    I'm a beginner, but I think that both beginners like me and advanced users will take advantage of this feature.

  9. #19
    Sencha Premium Member hsurya's Avatar
    Join Date
    Feb 2008
    Posts
    13
    Vote Rating
    1
      0  

    Default

    Although finally promise is incorporated limited to Ext.Ajax.request, it is quite late action. I feel sencha team is quite lazy. They are busy promoting without keeping with the pace of development. You see extjs 6.01, a lot of bugs since 6.0 and there is no official updates for more than 6 months (except for unofficial nightly builds for premium subscribers). Hellooooo sencha team, this is a warning. With good and totally free frameworks out there, such as ionic, u will be history soon if you don't improve yourself...!

  10. #20
    Sencha Premium Member
    Join Date
    Jul 2014
    Posts
    184
    Vote Rating
    154
      1  

    Default

    I personally don't want Sencha to be chasing what's cool. Promises got hot and cool but now that's old news and reactive programming is the cool thing. Expect them to keep up with the cool thing which may require breaking changes? I say they shouldn't do that.

    Ext.Ajax.request() can now accept then() now because it does one thing, it sends a request. But if you look at other things, you cannot sprinkle promises over things. Let's look at store.load(), per the documentation it returns the store instance. You cannot simply slap a then() on the store as the store does many things and then() could mean a multitude of things. Now if store.load() returned the operation it created then it could be like Ext.Ajax.request() where you could promisify it and keep backwards compatibility however it doesn't, you'd have to break the api in order to support it.

    Why does store.load() return the store when you already have the store as a variable? It's for chaining so you could do stuff like

    Code:
    store
      .load()
      .filter('foo', 'bar');
    I personally don't use it like that but Ext JS is used by a lot of people so you can't just assume no one is doing something like that. You could also have something like:


    Code:
    loadStore: function(store) {
        return store.load();
    }
    to return the store instance instead of having to do:

    Code:
    loadStore: function(store) {
        store.load();
    
        return store;
    }
    So Ext JS can't have promises spread around without breaking changes which if you've been part of the community for last few years they broke backwards compatibility with 4.0 and got flamed for it so they have only been breaking things for perf improvement or the merge with Sencha Touch.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •