Periodically_call_remote updates self to turn self off?

Sir Railists:

Oggle this pseudo-Rails:

<%= periodically_call_remote(:update => 'self', :action => 'yo' ... ) %>

def yo
if new_data
update :text => format(new_data)
else
update :text => periodically_call_remote(:update => ‘self’,

:action => 'yo' ... )
end

end

The intent is to update a div until new data appears, then display it
once
and stop updating the div.

I haven’t typed this in yet because I suspect it won’t work.

I suspect that the browser will evaluate the JavaScript representation
of
periodically_call_remote(), then spawn a window timer. The timer will
send
AJAX, and the reply will contain another JavaScript representation of
periodically_call_remote(). The new JavaScript will not turn off the
original timer. Then the browser will evaluate it and spawn a window
timer.
The effect will keep rolling along until the browser slows down with
lots of
simultaneous AJAX calls…

How to fix this? How to keep updating until data arrive, then stop?


Phlip
http://www.greencheese.us/ZeekLand ← NOT a blog!!!

On Wednesday, November 29, 2006, at 01:19PM, “Phlip”
[email protected] wrote:

The intent is to update a div until new data appears, then display it once
and stop updating the div.

I haven’t typed this in yet because I suspect it won’t work.

Your suspicions are correct. Do something like this (don’t call a div
‘self’… it might conflict with the Ruby Ojbect #self):

<%= periodically_call_remote(:url => {:action => 'updater'}, :frequency => 5, :condition => "stop_polling == false") %>

After you update the information in div ‘myself’ once, set ‘stop_polling
= true’.

cr

cremes.devlist wrote:

The intent is to update a div until new data appears, then display it once
and stop updating the div.

I haven’t typed this in yet because I suspect it won’t work.

Your suspicions are correct. Do something like this
(don’t call a div ‘self’… it might conflict with the Ruby Ojbect #self):

I trust my syntax hiliting. (:slight_smile:

Thanks - that’s just what I researched, based on this:

http://rubyforge.org/pipermail/backgroundrb-devel/2006-August/000248.html

I did what you said, much better than that post, with only two
improvements:

I didn’t put the periodically_call_remote() inside its own updated div!
(I
also don’t e-mail a new one back to myself!)

<%= periodically_call_remote(:url => {:action => ‘updater’},
:frequency => 5,
:condition => “stop_polling == false”) %>

And I followed the advice “state things positively”. So the variable is
‘keep_polling’, and the condition is one tick simpler:
:condition=>‘keep_polling’.

Now for my next magical trick, I shall add a number to stop_polling, to
make
it stop_polling_2, to put many of these naughty things all over my page!

(Going forward, I will replace every periodically_call_remote() with a
single one that intelligently updates with replace_html, only those divs
that have changed. But that is another story!)


Phlip
Redirecting... ← NOT a blog!!!