6.2 news: new Event management

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

6.2 news: new Event management

Janko Mivšek
Dear Aiders,

Let me explain the new Event management in Aida, which was inspired
mainly by Herbert's Christmas wish [1], but also on my recent study of
internal web browser workings and a node.js JavaScript based web server
[2]. 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
ideal.

So, now if you look at the new Aida Ajax demo
http://demo.aidaweb.si/demo.html?view=ajax, every event is reported to
Aida by a simple JavaScript code:

  <a onclick="aidaEvent('click','id6','62667'); "
   id="id6" href="javascript:nic()">Click me to update</a>

That's all, no more those long Prototype based JavaScript spaghetti as
before.

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:

        e update

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:

WebSecurityManagerApp>>loggedSesionsElement
  ...
  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].
  (e addNilLinkText: 'login')
     title: 'Click to logout';
     onClickDo: [aSession logout];
     onClickUpdate: e with: aSession.
  ^e

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 :)

Best regards
Janko

[1]
http://forum.world.st/Wish-list-open-for-your-wishes-tp3090016p3091441.html
[2] http://nodejs.org


--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida