[aida] 6.2 news: new Event management
janko.mivsek at eranova.si
Thu Feb 17 13:35:22 CET 2011
Let me explain the new Event management in Aida, which was inspired
mainly by Herbert's Christmas wish , but also on my recent study of
. All three influences talk about browser events (like mouse clicks)
and how to handle them.
Recent trend (as shown by node.js) namelly is to extend the browser's
event loop to the server side. Browser's event loop is also asynchronous
and never blocks, idea therefore is that server side event handling is
also asynchronous and never blocks. With Aida we are now close to that
So, now if you look at the new Aida Ajax demo
http://demo.aidaweb.si/demo.html?view=ajax, every event is reported to
<a onclick="aidaEvent('click','id6','62667'); "
On server side we have now a greatly expanded freedom to handle such
events in many different ways, like:
(e addNilLinkText: 'Click me')
onClickDo: ["some action"]; "action block, aka callback"
onClickUpdate: someElement; "recreate and update that element"
onClickUpdate: someElement with: someArgument;
onClickPopup: self popup; "lightboxed popup windows"
onClickPopup: self popup thenUpdate: someElement;
onClickClose; "close the popup window"
Also, you can update some web element simply by:
And whatever you like, not just during web request cycle. When some
outside event occurs, like email comes etc. If you browser is WebSocket
enabled, such update will be send immediately to the browser. Always
present Comet therefore!
This 'e update' aproach was influenced by Iliad's #markDirty, thanks
goes to Nicolas Petton for that!
A nice example of very lightweight ajaxified status toggling is included
in Aida, as admin see Security->Sessions->Logged-in or directly:
http://localhost:8888/sessions?view=logged. If you click 'login' in
first column, it will be changed to 'logout' and this session will be
logged out immediately.
To see how simple is now to achive that, here is the code:
grid := (WebGrid new width: self style pageContentWidth)
column: 2 addBlock: [:session | self stateElementFor: session];
and WebSecurityManagerApp>>stateElementFor: aSession
| e stateText |
e := WebElement new.
stateText := aSession loginStateText.
stateText = 'login' ifFalse:
[e addText: stateText.
(e addNilLinkText: 'login')
title: 'Click to logout';
onClickDo: [aSession logout];
onClickUpdate: e with: aSession.
One of the important new feature is that an second argument to the
#onClickUpdate:with: can be now any object and not only string. This
then allows such a simple code as shown above.
You are invited o explore and start using that new event management and
come out which some new wish for inspiration to go eve further :)
Smalltalk Web Application Server
More information about the Aida