Add onComplete for Ajax.PeriodicalUpdater
Reported by David Beckwith | April 14th, 2008 @ 06:49 AM | in 1.6.1
Hi,
As far as i understand things, Ajax.PeriodicalUpdater's internal Ajax.Updater's callback onComplete has been overwritten by Ajax.PeriodicalUpdater#updateComplete, which prevents one from being able to customize the onComplete of the internal Ajax.Updater instance. I'm proposing a new option for Ajax.PeriodicalUpdater called onEachComplete, which, when set to a function, calls that function when the internal Ajax.Updater instance's onComplete callback is called. (phew what a mouthful.) The work around I have seen on the web is to use onSuccess, but that delays the calling of your custom function to the next call to Ajax.Updater.
I'm proposing to add 3 lines of code to the definition of Ajax.PeriodicalUpdater in prototype.js:
updateComplete: function(response) {
if (this.options.onEachComplete){
this.options.onEachComplete(this);
}
To use this cusomization, you would do something like this:
new Ajax.PeriodicalUpdater("current_box", "/boxes/1.json", {
method: 'get',
frequency : 5,
decay : 1.1,
onEachComplete: get_poll_data
});
This is my first attempted contribution, sorry for not following the protocol. I'm not sure exactly what to do. I'll post this to the google group as well.
Comments and changes to this ticket
-
Andrew Dupont April 14th, 2008 @ 10:36 AM
- → State changed from new to open
- → Title changed from Feature enhancement: onEachComplete for Ajax.PeriodicalUpdater to Add onComplete for Ajax.PeriodicalUpdater
My preference would be simply that @Ajax.PeriodicalUpdater@'s internal
onCompletecallback not step on a user-defined callback. We'd talked about doing that a while back but never did.Thanks for the suggestion.
-
Tobie Langel April 16th, 2008 @ 10:07 PM
- → State changed from open to patch_needed
- → Title changed from [ENH] Add onComplete for Ajax.PeriodicalUpdater to Add onComplete for Ajax.PeriodicalUpdater
-
Tobie Langel April 18th, 2008 @ 01:18 PM
- → State changed from patch_needed to enhancement
-
Andrew Dupont April 21st, 2008 @ 07:58 PM
- → Milestone changed from to 1.6.1
- → Assigned user changed from to Andrew Dupont
-
Mark Caudill August 27th, 2008 @ 05:37 AM
- → Tag changed from to ajax needs_docs needs_tests patched
Here is a patch that (likely) solves this. I also made a small addition to the ajax test (just for kicks). This patch would have to apply before my patch for Ajax.abort: http://prototype.lighthouseapp.c...
I tried a couple of things, but the fastest route is just to create a new object of the options and overwrite the onComplete. The unfortunate side effect is that people would have to manually adjust the options via .ajaxOptions instead of .options. Creating a new object when onTimerEvent is run is the only realistic way to get around this.
-
Mark Caudill August 27th, 2008 @ 08:13 AM
Some changes after talking with JDD about the patch I made earlier. This actually adds correct support for onComplete and just creates an object inside the onTimerEvent because otherwise it would be a big change from the current setup. Also, onStop was added which now only triggers after .stop() is called.
-
John-David Dalton August 27th, 2008 @ 09:09 AM
I was thinking more along the lines of this: "0001-Ajax.PeriodicalUpdater-Change-the-onComplete-option.patch"
-
John-David Dalton August 27th, 2008 @ 09:36 AM
- no changes were found...
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
