I have a little time today, so I figured I would start coding up a little app using this new RIA framework called Appcelerator that I have been introduced to in the last month by some PR representatives from the framework’s development company. At first I thought that I needed another RIA framework to consider like I needed a hole in my head, but a few things caught my eye initially about the framework:
- You write code in XHTML and CSS, with some JavaScript (so far I haven’t had to write a single line)
- Hand in glove integration with popular server-side languages (Java, Ruby, PHP, Python)
- Event driven UI through a neat messaging framework built in to the Web Expression Language
Numbers 1 and 2 are nice, but number three is where Appcelerator has me very excited. I am in the process of refactoring ReCESS to use the Cairngorm Micro-architecture. A big reason for that is to make the UI more event driven. But that process is turning out to be rather tiresome, as every time I want to create a new event, I need to write six ActionScript classes to implement it. Lame. The good part about it is that Cairngorm provides a nice level of abstraction between back-end server data (coming in the form of XML, JSON, whatever) and my UI logic, because my UI can bind to domain-specific models rather than raw XML. But the whole messaging piece is kind of cumbersome, and requires a lot of work to do something that should be easy.
Enter Appcelerator’s messaging system - let’s say I have a link, and when that link is clicked I want to make a block of HTML pulsate for effect. I would do something like this:
<a on="click then l:link.clicked.event">Click Me To Do Stuff!</a>
<div on="l:link.clicked.event then effect[Pulsate]">
<p> This is important text </p>
</div>
What is happening here is that an event called “link.clicked.event” is being published when the link is clicked. The div block on the next line is subscribing to that event, and when that event is published, will make the contents of the div pulsate (using Script.aculo.us under the covers I think). No scripting necessary to make this happen. Server interaction is handled via this messaging framework, but I’ll get into that in another post. The utility of this publish/subscribe method should be clear - when I need something else to happen when that click event is published, all I have to do is subscribe again:
<a on="click then l:link.clicked.event">Click Me To Do Stuff!</a>
<div on="l:link.clicked.event then effect[Pulsate]">
<p> This is important text </p>
</div>
<div on="l:link.clicked.event then show" style="display:none">
<p> This text will be visible after the click </p>
</div>
Cool beans. To do that same event-driven goodness in Flex, I would have to either write a script to execute when the link was clicked to procedurally pulsate or show the text if I was being sloppy, or create a Cairngorm Event and Command, register them with the front controller, and create new state variables in my model locator to toggle visibility and whatnot. Again, it works pretty well, but I just did that same thing here in Appcelerator with a tiny fraction of the code.
More to come on the overall Appcelerator experience, but after my first few minutes actually coding with Appcelerator, I thought that easy messaging system was the bee’s knees. It was kind of an adventure getting my dev environment set up, but the project is still young (and based on my brief experience, full of potential as well).