воскресенье, 15 мая 2011 г.

Promoting dependency management to the web page with Lift framework

Just finished reading Simply Lift chapter about WiringUI. David Pollak is fucking genius!!! He promoted the idea of functional dependency management to web page scope.

Let's imagine you have some variable which introduces lot's of calculations based on it's value. In any full featured functional language one can define dependent values as a function applications that should be done to calculate final value based on dependent ones. This way you can pass around this applications and get actual values every time the function is executed.

With little functional voodoo you can now identify the changes to dependent variables when changing the dependency. And based on that generate a JavaScript doing this changes on the page(based on previously defined structure of variables placement in DOM tree).

Now for the real world example: you have a page with video player and a playlist. Also there is a currently playing item in the playlist. Also the playlist is manageable in a classic way(add, remove, play item).

So now you define that player depends on the current item and links to all playlist management functionality are doing atomic updates to it. Now you wire the stuff together in one place(source code of course) and BAM!!! Everything is working just as expected. It's really that simple(I tryed myself).

Plus you can combine all of that with Lift builtin Comet and create something like a webcast right on the webpage. Anyone just opens up a page an makes update to the playlist switching the currently playing item and everyone viewing it would receive the same live updates via Comet. It's long polling and cheap cause it's using continuations to keep you safe. Or you might want to create rooms of some sort. This also requires not too much code.

Everyone who's interested in Scala or/and functional programming even a little should definitely take a look on that. A little of abstract thinking would help to cut away the Lift specifics and get the main idea.

Комментариев нет:

Отправить комментарий