Tom Fakes
2005-Dec-21 19:38 UTC
RE: Prototype: correct useage of onCompletewithAjax.PeriodicalUpdater
The only call that PeriodicalUpdater will make periodically to you is the insertion call. I think of onComplete as being ''I''ve done everything I was going to do'', which for Updater is right after it''s done a single update, but for PeriodicalUpdater, it''s after it''s finished all of its updates, so you''ll only get it once for any call of ''new''. This allows you to do any cleanup you need to do. The Ajax.Responders is probably a better place for progress indication to be placed anyway. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Nicky Peeters Sent: Wednesday, December 21, 2005 11:31 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Prototype: correct useage of onCompletewithAjax.PeriodicalUpdater Tom, Thanks for your reply, unfortunately I need to execute a function *after* the insertion of received content into the container, specifically to remove my progress-indication content. I could ofcourse write the insertion code myself, and add the other code in there, but since the onCompletes registered with Ajax.Responders work the removing of progress indication HTML should be better executed there. My current code works flawlessly using the onSuccess code to remove all progress indication HTML... I tried to throw a Venkman debugging sessions at the problem, but still fail to grasp how PeriodicalUpdater differs from Updater in respect to the dispatching of onComplete functions... Thx, Nicky On 21 Dec 2005, at 20:17, Tom Fakes wrote:>> From a quick look at the source code, it looks like onComplete is >> only > called when the whole thing is done - in the case of Updater, right > after the update, in the case of PeriodicalUpdater, right after it has > been stopped. > > It looks like you need to pass your callback method as an ''insertion'' > method in the options. This takes two parameters, the first will > probably be the first parameter you passed to new > PeriodicalUpdater, the > second will be the response. > > e.g. > > new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', > { > insertion: function (element, request){fooBar()}, > onLoading: function(request){ showProgress()}, > parameters: params, > asynchronous:true, > decay:2, > frequency:20.0 > }); > > -----Original Message----- > From: Nicky Peeters [mailto:nicky.peeters-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org] > Sent: Wednesday, December 21, 2005 7:13 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Prototype: correct useage of onComplete > withAjax.PeriodicalUpdater > > Hello all, > > I know it''s a Prototype question, but I hope someone can tell me what > I''m doing wrong (I hope Prototype gets documented soon ;-( > > Problem: using a onComplete callback with Ajax.PeriodicalUpdater > (using scriptaculous 1.5 with Prototype 1.4) > > Works: > function fooBar() { > Element.hide(''foobar''); > } > > new Ajax.Updater(''buddies-and-locations'', ''/ajax-url'', > { asynchronous:true, > onComplete: function(request) {fooBar();}, > onLoading: function(request) {showProgress();}, > parameters: params > }); > > Will not work when using a onComplete callback in the same manner : > > new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', > { > onComplete: function (request){fooBar()}, > onLoading: function(request){ showProgress()}, > parameters: params, > asynchronous:true, > decay:2, > frequency:20.0 > }); > > But registering the onComplete using Ajax.Responders DOES work : > > Ajax.Responders.register({ > onCreate: function() { > if($(''buddies-loading-notice'') && Ajax.activeRequestCount>0) > showProgress(); > }, > onComplete: function() { > if($(''buddies-loading-notice'') && Ajax.activeRequestCount==0) > fooBar(); > } > }); > > I tried passing the callback in various forms (return function()..., > this.fooBar().bind(this) etc...) > I worked around the problem using onSuccess in the PeriodicalUpdater > (is that problematic?) > > Is it normal that onComplete callbacks do not work in the > Ajax.PeriodicalUpdater ? > > Thanks alot, > > Nicky Peeters > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Nicky Peeters
2005-Dec-21 20:01 UTC
Re: Prototype: correct useage of onCompletewithAjax.PeriodicalUpdater
Tom, Sorry that my brain was pretty slow this evening (just come of a day''s work and some pain-inducing Venkman sessions) ! I now understand the difference in execution between PeriodicalUpdater and Updater. And it seems very logical indeed. It''s onComplete of all update- cycles, while onSuccess is more suitable ''cause of its ''per-ajax- call'' semantics. I assume then when using the stop() method on the PeriodicalUpdater the onComplete callback WILL be called for cleanup ;-) Well I''m off to confirm my suspicion above with some more digging into prototype.js. Thanks very much for your replies ! Nicky Peeters Belgium On 21 Dec 2005, at 20:38, Tom Fakes wrote:> The only call that PeriodicalUpdater will make periodically to you is > the insertion call. > > I think of onComplete as being ''I''ve done everything I was going to > do'', > which for Updater is right after it''s done a single update, but for > PeriodicalUpdater, it''s after it''s finished all of its updates, so > you''ll only get it once for any call of ''new''. This allows you to do > any cleanup you need to do. > > The Ajax.Responders is probably a better place for progress indication > to be placed anyway. > > -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of > Nicky > Peeters > Sent: Wednesday, December 21, 2005 11:31 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] Prototype: correct useage of > onCompletewithAjax.PeriodicalUpdater > > Tom, > > Thanks for your reply, unfortunately I need to execute a function > *after* the insertion of received content into the container, > specifically to remove my progress-indication content. I could > ofcourse write the insertion code myself, and add the other code in > there, but since the onCompletes registered with Ajax.Responders work > the removing of progress indication HTML should be better executed > there. > > My current code works flawlessly using the onSuccess code to remove > all progress indication HTML... > I tried to throw a Venkman debugging sessions at the problem, but > still fail to grasp how PeriodicalUpdater differs from Updater in > respect to the dispatching of onComplete functions... > > Thx, > > Nicky > > On 21 Dec 2005, at 20:17, Tom Fakes wrote: > >>> From a quick look at the source code, it looks like onComplete is >>> only >> called when the whole thing is done - in the case of Updater, right >> after the update, in the case of PeriodicalUpdater, right after it >> has >> been stopped. >> >> It looks like you need to pass your callback method as an ''insertion'' >> method in the options. This takes two parameters, the first will >> probably be the first parameter you passed to new >> PeriodicalUpdater, the >> second will be the response. >> >> e.g. >> >> new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', >> { >> insertion: function (element, request){fooBar()}, >> onLoading: function(request){ showProgress()}, >> parameters: params, >> asynchronous:true, >> decay:2, >> frequency:20.0 >> }); >> >> -----Original Message----- >> From: Nicky Peeters [mailto:nicky.peeters-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org] >> Sent: Wednesday, December 21, 2005 7:13 AM >> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Subject: [Rails-spinoffs] Prototype: correct useage of onComplete >> withAjax.PeriodicalUpdater >> >> Hello all, >> >> I know it''s a Prototype question, but I hope someone can tell me what >> I''m doing wrong (I hope Prototype gets documented soon ;-( >> >> Problem: using a onComplete callback with Ajax.PeriodicalUpdater >> (using scriptaculous 1.5 with Prototype 1.4) >> >> Works: >> function fooBar() { >> Element.hide(''foobar''); >> } >> >> new Ajax.Updater(''buddies-and-locations'', ''/ajax-url'', >> { asynchronous:true, >> onComplete: function(request) {fooBar();}, >> onLoading: function(request) {showProgress();}, >> parameters: params >> }); >> >> Will not work when using a onComplete callback in the same manner : >> >> new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', >> { >> onComplete: function (request){fooBar()}, >> onLoading: function(request){ showProgress()}, >> parameters: params, >> asynchronous:true, >> decay:2, >> frequency:20.0 >> }); >> >> But registering the onComplete using Ajax.Responders DOES work : >> >> Ajax.Responders.register({ >> onCreate: function() { >> if($(''buddies-loading-notice'') && Ajax.activeRequestCount>0) >> showProgress(); >> }, >> onComplete: function() { >> if($(''buddies-loading-notice'') && Ajax.activeRequestCount==0) >> fooBar(); >> } >> }); >> >> I tried passing the callback in various forms (return function()..., >> this.fooBar().bind(this) etc...) >> I worked around the problem using onSuccess in the PeriodicalUpdater >> (is that problematic?) >> >> Is it normal that onComplete callbacks do not work in the >> Ajax.PeriodicalUpdater ? >> >> Thanks alot, >> >> Nicky Peeters >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Seemingly Similar Threads
- RE: Prototype: correct useage of onComplete withAjax.PeriodicalUpdater
- Prototype: correct useage of onComplete with Ajax.PeriodicalUpdater
- PeriodicalUpdater onComplete broken?
- Yet another periodicalupdater question
- Stopping the Ajax.PeriodicalUpdater -- My Kludge?