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