RE: SUPeriodical - changing the frequency on the fly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: SUPeriodical - changing the frequency on the fly

Ramon Leon-5
> Hello,
>
> I am trying to change the frequency of  aSUPeriodical on the
> fly but what I am doing does not work.  I create an instance
> of SUPeriodical with a frequency of 10 seconds.  That works
> fine, the SUPeriodical is triggered every 10 seconds.  I then
> change the frequence of the same instance of SUPeriodical to
> 30 seconds but it continues being triggered every 10 seconds.
>
> I have examined the SUPeriodical instance and confirmed that
> its frequency has been changed to 30.
>
> Am I doing something wrong?
>
> Thanks,
> Frank
>

Umm... I'm not sure you can do this.  First off, as far as I know, these are
transient objects, used to generate JavaScript and then disposed of during
the rendering phase.  Holding onto an instance and editing it will likely do
nothing as the client side JavaScript has already been generated.  Can you
show your code to confirm?

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: SUPeriodical - changing the frequency on the fly

Ramon Leon-4
>
> I think that I am starting to see why this will not work and I am begining
> to understand what you said.  I suspect that SUPeriodical will only render
> the paragraph containing the "script".  Because the whole html page is not
> re-written, the javascript code in the page is not updated with the new
> frequency.  Is this correct?
>
> ... Frank

Right, the periodical only updates the contents of the paragraph, it
does not rerender itself.  Doing so would likely start two periodicals
on the client side, it'd act as a new one, but the old one would
probably still be running.  You could reuse a periodical over many
different renders, but it'd render a new client side instance each time,
it wouldn't update the existing one.

When I said the object was transient, I meant that they're a thin veneer
over the client side JavaScript library, they aren't server side objects
per se.  Treat them like you would treat any other render method,
they're for rendering, not really meant for storing in instance
variables or reusing.

If you dig around and look at how they work, they basically get
interpreted into equivalent JavaScript strings that get tagged onto/into
the generated html.  Hunt down the javascriptOn: messages in the image
to see how they work.

The canvas API is html in Smalltalk syntax, scriptalicious is basically
JavaScript in Smalltalk.  Of course, there's not a lot of documentation,
this is my understanding of how things work from my own experience, I
could well be wrong.

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: SUPeriodical - changing the frequency on the fly

Lukas Renggli
> The canvas API is html in Smalltalk syntax, scriptalicious is basically
> JavaScript in Smalltalk.  Of course, there's not a lot of documentation,
> this is my understanding of how things work from my own experience, I
> could well be wrong.

This is correct. Still it is possible to do what the original poster
requested. The trick is to assign the periodical updater to a
variable, not on the smalltalk side but on the JavaScript side. This
can be done like this:

html periodical
     configMsg1;
     configMsg2;
     configMsg3;
     assignLocalTo: 'per'

Now in a different rendering pass you can reference the existing
periodical updater (and not creating a new one) by doing something
like this:

html periodical
    alias: 'per';
    configMsg4;
    configMsg5

Hope this helps.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Re: Re: SUPeriodical - changing the frequency on the fly

Ramon Leon-5
> This is correct. Still it is possible to do what the original
> poster requested. The trick is to assign the periodical
> updater to a variable, not on the smalltalk side but on the
> JavaScript side. This can be done like this:
>
> html periodical
>      configMsg1;
>      configMsg2;
>      configMsg3;
>      assignLocalTo: 'per'
>
> Now in a different rendering pass you can reference the
> existing periodical updater (and not creating a new one) by
> doing something like this:
>
> html periodical
>     alias: 'per';
>     configMsg4;
>     configMsg5
>
> Hope this helps.
>
> Lukas

Hmm, interesting, I wasn't aware of assignLocalTo:, cool.

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: SUPeriodical - changing the frequency on the fly

Lukas Renggli
In reply to this post by Lukas Renggli
> Is there any way to do what I want using Scriptaclous?

Sure, try something like this:

        html div
                id: 'time';
                script: (html periodical
                        frequency: frequency;
                        callback: [ :r | r render: Time now ];
                        assignTo: 'updater');
                with: Time now.

        html div id: 'track'; with: [ html div id: 'handle' ].
        html script: (html slider
                handleId: 'handle';
                trackId: 'track';
                value: frequency;
                range: (1 to: 10);
                onChange: (SUStream on: 'console.log("change",
arguments);updater.stop();updater.frequency=arguments[0];
updater.start();'))

The last part is slightly ugly as I wrote some bare JavaScript. You
could archive exactly the same by composing a script like:

html javascript
     add: (html periodical
         alias: 'periodical';
         stop):
     add: (html periodical
         ....

but this gets too cumbersome in my opinion. I usually suggest that you
write more complicated functionality in bare JavaScript (use #script
or a class extension to SULibrary) and call it from your code using
simple configurable objects. This scales usually much better.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: SUPeriodical - changing the frequency on the fly

Lukas Renggli
>         html div id: 'track'; with: [ html div id: 'handle' ].
>         html script: (html slider
>                 handleId: 'handle';
>                 trackId: 'track';
>                 value: frequency;
>                 range: (1 to: 10);
>                 onChange: (SUStream on: 'console.log("change",
> arguments);updater.stop();updater.frequency=arguments[0];
> updater.start();'))

Ahh, maybe remove the console.log statement, this was just for me to test ;-)

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: SUPeriodical - changing the frequency onthe fly

Lukas Renggli
In reply to this post by Lukas Renggli
> 1. Where does  the "arguments[0]"  - come from?  who fills in the array
> "arguments"?

"arguments" is an implicit variable available within any function
body. It is a bit like thisContext in Smalltalk. You can access the
arguments using the array syntax, so the above code will return the
first argument passed to the function. The generated JavaScript code
for functions never give propre names to arguments and always uses
indexes when accessing the values.

See also <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:arguments>

> 2. I see in your example code that you have a line of debugging code:
> 'console.log("change", arguments)'.  Does this result in the information
> being written tothe Javascript console?  This would be so useful but in my
> environment it complains about "console".  How do I get this to work?

This only works in the WebKit version of Safari (older version even
crash) or in FireFox with the FireBug (a mandatory tool to use when
using script.aculo.us) extension loaded. As far as I know
"console.log" is an upcoming standard to JavaScript, so better suport
for that construct is to be expected.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside