Archive for the ‘PureMVC’ Category

PureMVC-like Notification Mediator in Cairngorm

Caveat: My experience with PureMVC is limited to reading the excellent docs and a few blogs. Also, this post is total bait to get Ben Rimbey and Benjamin Corliss to blog a bit. 😛 

So, PureMVC has a “Mediator” that sits between your UI and the View singleton. One of it’s jobs is too respond to PureMVC Notifications. Here’s what that looks like from the docs:

override public function handleNotification( note : INotification ) : void {
 switch ( note.getName() ) {
  case ApplicationFacade.SEARCH_FAILED:
    controlBar.status = AppControlBar.STATUS_FAILED;

 case ApplicationFacade.SEARCH_SUCCESS:
    controlBar.status = AppControlBar.STATUS_SUCCESS;


So when you get a Notification with the name ApplicationFacade.SEARCH_FAILED or ApplicationFacade.SEARCH_SUCCESS it’s handled in the switch. I have a couple philosophical problems with this approach because the View should be a representation of the Model and the Model should maintain the state of the application. Adding the ability for the View or Control to talk directly to the View seems dangerous.

I’m not saying Cairngorm is teh awesomes, but here’s an easy way to achieve the same affect and maintain the state in the Model. I’ll use a for-reals life example…

In the mxml:

<?xml version="1.0" encoding="utf-8"?>
    currentState="{ model.complete ? 'complete' : 'scanning' }"

    <!-- State changes are handled in the code behind -->
        <mx:State name="scanning" enterState="enterScanningState( event )" />
        <mx:State name="complete" enterState="enterCompleteState( event )" />

Okay. So this particular example binds the state to model.complete, but you could just as easily bind it to model.currentScanState or whatever. Then the code-behind has the enterScanningState and enterCompleteState handlers in it. Meh?