1. #1
    Sencha Premium Member
    Join Date
    Feb 2013
    Posts
    1
    Vote Rating
    0
    gloria.gu@hp.com is on a distinguished road

      0  

    Default Unanswered: How can I get fireEvent to wait for the event to return value

    Unanswered: How can I get fireEvent to wait for the event to return value


    I have the following code in my view:

    isValid : function(){
    var retValue = this.fireEvent("checkValidSave");
    return retValue;
    }

    The checkValidSave event handler will call the method saveSettings in controller. saveSettings will return true or false based on whether or not it saves successfully.

    The problem is when fireEvent calls , it fires event , but it returns immediately while the event is still in progress.


    Based fireEvent description in sencha doc, regarding return ....

    Returns
    • Booleanreturns false if any of the handlers return false otherwise it returns true.
    How to make the fireEvent to wait for the even handler to finish and return proper value?


    Gloria Gu

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,062
    Vote Rating
    215
    Answers
    486
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    I tried abstracted your example and it looks like the response from fireEvent is being captured. If I return false then the result of calling fireEvent is false. If I return true it's true.

    Code:
    var listener = new Ext.util.Observable({
        listeners: {
            checkValidSave: function () {
                //return true;
                return false;
            }
        }
    });
    
    
    Ext.widget('button', {
        renderTo: document.body,
        text: 'Fire Event',
        handler: function (btn) {
            var saved = listener.fireEvent('checkValidSave', btn);
            console.log(saved);
        }
    });


    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager:
    sheryl@sencha.com

  3. #3
    Sencha User
    Join Date
    Jan 2008
    Location
    Los Angeles
    Posts
    149
    Vote Rating
    1
    Answers
    1
    radtad is on a distinguished road

      0  

    Default


    Quote Originally Posted by slemmon View Post
    I tried abstracted your example and it looks like the response from fireEvent is being captured. If I return false then the result of calling fireEvent is false. If I return true it's true.

    Code:
    var listener = new Ext.util.Observable({
        listeners: {
            checkValidSave: function () {
                //return true;
                return false;
            }
        }
    });
    
    
    Ext.widget('button', {
        renderTo: document.body,
        text: 'Fire Event',
        handler: function (btn) {
            var saved = listener.fireEvent('checkValidSave', btn);
            console.log(saved);
        }
    });
    This works, but it returns right away if there is a buffer which it shouldn't do. Any way around this? It should probably at the least block on the buffering right?

    Code:
        var listener = new Ext.util.Observable({
            listeners: {
                checkValidSave: {
                    fn: function () {
                        //return true;
                        return false;
                    },
                    buffer: 2000
                }
            }
        });
    
    
    
    
        Ext.widget('button', {
            renderTo: 'grid',
            text: 'Fire Event',
            handler: function (btn) {
                var saved = listener.fireEvent('checkValidSave', btn);
                console.log(saved);
            }
        });

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,170
    Vote Rating
    674
    Answers
    474
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    No, because buffering works with setTimeout, there's no way to "block" the thread. You'd need to pass some kind of callback that it could execute.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Sencha User
    Join Date
    Jan 2008
    Location
    Los Angeles
    Posts
    149
    Vote Rating
    1
    Answers
    1
    radtad is on a distinguished road

      0  

    Default


    Quote Originally Posted by evant View Post
    No, because buffering works with setTimeout, there's no way to "block" the thread. You'd need to pass some kind of callback that it could execute.
    Figured as much. I'm writing a base controller to fire an event and do validation within it like this. Other employees will be writing controllers that will be listening to a custom event fired within the base controller (application fireEvent) and I'm just worried someone will put a buffer on the listener for the custom event and screw everything up.

    Is there anyway to tell the listener upon firing the event to not use its buffer if it has one?

  6. #6
    Sencha User
    Join Date
    Oct 2014
    Posts
    2
    Vote Rating
    0
    YumTraX is on a distinguished road

      0  

    Default Add Callback

    Add Callback


    Quote Originally Posted by evant View Post
    No, because buffering works with setTimeout, there's no way to "block" the thread. You'd need to pass some kind of callback that it could execute.
    How to do so? I am facing the same problem as my Logout Controller needs to wait for other controllers which do some syncing, deleting local storage... before the Logout Controller can actually log out and end the session.

    greetz

Thread Participants: 4

Tags for this Thread