Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

onSuccess executed only if onComplete checks succeeds .. #2730

Open
imbibinebe opened this issue Aug 25, 2015 · 1 comment
Open

onSuccess executed only if onComplete checks succeeds .. #2730

imbibinebe opened this issue Aug 25, 2015 · 1 comment

Comments

@imbibinebe
Copy link

Hi there
I develop a mobile app with a
controller > view architecture combined with asynchronous AJAX requests.
In order to avoid memory leaks, in destroy current controller and view (DOM) when the user switch back to a previous view ([back] button ...)
My onSuccess method uses to update the view depending on data retrieved from the AJAX call and that's why I don't want it to be executed if the user left this view cause it's not surprisingly generating javascript errors ...
tests I have to do are always the same and that's why i didn't want to put them in each of my onSuccess methods (many) since I have an onComplete method which is common to all my requests.
Then here is what I do:

onComplete: function(e)
{
         if(my tests are not OK) {
                this.removeEvents().setOptions({timeout:0}).cancel();
                return;
         }
         ...
         few other things if tests are OK
         ...
}

This is working correctly (onSuccess method is not executed) if the user switch back fast enough on the previous view ([back] button) but not if he waits to long (like 0.5 or 1s more).
Here is what is see in mootools-core source code.

onSuccess: function(){
        this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
    },

I thought that onSuccess method were executed only when onComplete method has finished. Isn't it the case ?
Do you have an idea of how I should do ?

Best

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@DimitarChristoff
Copy link
Member

these are internal handlers

https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.js#L106-L116

I would probably prefer to have the this.fireEvent('complete')
independent, preceding this line:
https://github.com/mootools/mootools-core/blob/master/Source/Request/Request.js#L82

On 25 August 2015 at 22:08, Tin LE GALL notifications@github.com wrote:

Hi there
I develop a mobile app with a
controller > view architecture combined with asynchronous AJAX requests.
In order to avoid memory leaks, in destroy current controller and view
(DOM) when the user switch back to a previous view ([back] button ...)
My onSuccess method uses to update the view depending on data retrieved
from the AJAX call and that's why I don't want it to be executed if the
user left this view cause it's not surprisingly generating javascript
errors ...
tests I have to do are always the same and that's why i didn't want to put
them in each of my onSuccess methods (many) since I have an onComplete
method which is common to all my requests.
Then here is what I do:

onComplete: function(e)
{
if(my tests are not OK) {
this.removeEvents().setOptions({timeout:0}).cancel();
return;
}
...
few other things if tests are OK
...
}

This is working correctly (onSuccess method is not executed) if the user
switch back fast enough on the previous view ([back] button) but not if he
waits to long (like 0.5 or 1s more).
Here is what is see in mootools-core source code.

onSuccess: function(){
this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
},

I thought that onSuccess method were executed only when onComplete method
has finished. Isn't it the case ?
Do you have an idea of how I should do ?

Best


Reply to this email directly or view it on GitHub
#2730.

Dimitar Christoff

"JavaScript is to JAVA what hamster is to ham"
@D_mitar - https://github.com/DimitarChristoff

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@DimitarChristoff @imbibinebe and others