Ramblings

March 31, 2008

Cairngorm and views responding to server side events

Filed under: cairngorm, education, flex — michaelangela @ 6:26 pm

I’ll have to dig up the links for this as a reference. But I started an app in Flex. I wanted a good framework to work with to help me organize the code, get some “best practices”, etc. I chose the then standard Cairngorm currently hosted at Adobe. Everything was happening client side so all was good. That was because with Flex, you can use data binding. That means your user interface elements can simply be “bound” to a certain bit of data. When the data updates, the UI element updates, automatically. That’s cool.

However I started to add server side processing. UI controls mapped directly to data, even data processed on the server side, is still updated automatically. However, what if I want to notify the user that data on the server has finished? How do I notify different UI elements about such things as “your data is saved”, “your data is NOT saved”, etc.?

Linking that sort of data becomes hard to do, and also hard to maintain. I seemed to be at a loss of what to do. This is where the reference links would come in. There was actually quite a bit of discussion about this and, in the end, what I needed, or at least what I concluded, was actually not recommended for Cairngorm.

In Cairngorm, you have models and you have views. (You also have controllers to complete the MVC pattern.) When your model changes (meaning your data changed), your views which are bound to the model update. This doesn’t leave room for UI notifications, etc. The pattern I found that I was after is called ViewHelpers or ViewLocator. Basically it’s a way to wire your views to listen for events for updates, specifically for user notifications.

There was even a good post about why you should just add responders to a Cairngorm event so that the view can be notified directly as a callback on that event. That’s good… except it makes the assumption that the only view interested in that event is the one that triggered the event. That’s not always the case.

I hit this because I wanted to do drag and drop from one Flex UI component to another. When the user drops the object, an event is fired to save data to the server. The originator of the event though was the not the view I wanted to update. I eventually did find ViewLocator/ViewHelper patterns to use, which helped tremendously, even though others disagree with the implementation.

Interestingly enough, a newer Flex framework called PureMVC doesn’t have these issues. The idea of any view being able to be notified by any event is assumed. If I have time, I will try to learn that system as it seems to be closer to the way I think… or perhaps how I want to think. 🙂

The following link has a good discussion about Cairngorm in general… just here for my own reference.

Flex and Flash Developer – Jesse Warden dot Kizz-ohm » Blog Archive » Cairngorm vs. Joe Berkovitz’s MVCS

Advertisements

2 Comments »

  1. […] factories for xml in > VO out Posted on April 11, 2008 by michaelangela I’ve linked to this article before but I wanted to bring up another point now. I have a good xml data set that is becoming the local […]

    Pingback by Cairngorm factories for xml in > VO out « Ramblings — April 11, 2008 @ 5:56 pm

  2. […] factories for xml in > VO out Posted on April 11, 2008 by michaelangela I’ve linked to this article before but I wanted to bring up another point now. I have a good xml data set that is becoming the local […]

    Pingback by Cairngorm factories for xml in > VO out « Ramblings — April 11, 2008 @ 6:17 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: