[Seaside] Re: Sending messages to javascript objects

Andres Fortier andres at lifia.info.unlp.edu.ar
Fri Apr 25 19:38:01 UTC 2008

Hi everybody,
                       thanks for the replies. So it 
seems that there is no standard solution :(. What I am 
thinking about is in modelling a scripting environment, 
in Smalltalk, that would be translated into javascript. 
So far I got the following things:

- A ScriptingEnvironment. This object is rendered 
inside a div, with it's own particular id and is where 
the javascript will be dynamically placed (btw, I 
really don't like the name "Scripting Environment", but 
I couldn't come up with something better).
- An extension to the WARenderCanvas to support the 
message #scriptingEnvironment.
- The objects that will receive messages dynamically 
must have an id (and maybe in the future they will have 
to be subclass of a specific class -something like 

So the idea is to do things like:

env:=(html scriptingEnvironment
			callback: [:renderer | | proxy |
							proxy:=self map scriptingProxy.
							proxy enableGoogleBar.
							renderer render: proxy.

html checkbox
		value: (self map isEnabled: anItemName);
		onChange: env.

the proxy via #dnu: encodes the message as a javascript 
message send and the idea is that a scripting 
environment uses an updater to reload a div, where the 
script is coded, thus reinterpreting the script and 
effectively sending the messages to the javascript 
objects. This objects are defined as global variables 
in the /window/ object, and thus are global to all 
scripts. This last part is kind of a hack, but it works 
ok (at least on FF).

Now, what I would really like to have is:

env:=(html scriptingEnvironment
				callback: [self map enableGoogleBar].

and that the code inside the block is reinterpreted 
because it is being executed in a scripting 
environment; this means that the messages should be 
sent to the proxy and the proxy should be rendered 
afterwards. I'm looking into BlockContext at the moment 
to see if this is possible. If we could do such a thing 
we could dynamically send messages to javascript, but 
writing everything as we are used in Smalltalk.

Any ideas are most appreciated.

Thanks again,

Igor Stasenko escribió:
> 2008/4/25 Ramon Leon <ramon.leon at allresnet.com>:
>>> And finally, don't forget that we need to add new script to
>>  > #updateRoot:
>>  Why?
>>  >
>>  > updateRoot: htmlRoot
>>  >   htmlRoot addScript: self foo.
>>  >
>>  > What i don't like in code above:
>>  > - script it is added manually, it would be more convenient to
>>  > add it automatically (as result of call to html callMethod:
>>  > #foo of: ...)
>>  > - html root having no option to inline script in html,
>>  > instead it generates <script src=..>, it would be good to
>>  > have an option (a method, like WAHtmlRoot>>addScriptInline:,
>>  > which will generate script with source inlined on page,
>>  > because browser losing much more time to load script using
>>  > separate request rather than simply parse few lines of code ,
>>  > and if your page contains too much scripts , a page load time
>>  > can be  slowed down dramatically.
>>  You most certainly can render inline script directly, no need to attach to
>>  head...
>>  renderContentOn: html
>>   html script: 'alert("hello")'
> This is not an option, suppose i'm using a component which represents
> an item in list.
> Now, for each item in list it will call  html script: '' and produce
> many <script> tags for each item, while i need to add it only once.
>>  Ramon Leon
>>  http://onsmalltalk.com
>>  _______________________________________________
>>  seaside mailing list
>>  seaside at lists.squeakfoundation.org
>>  http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

More information about the seaside mailing list