Getting your head around the Mate framework

Actionscript, Flex Add comments

So I’ve been looking at Mate and trying to get my head around the way it manages the MVC process. The main difference between Mate and Cairngorm and the one thing I’ve been struggling to fix in my head is the relationship between the Views and the Model.

In Cairngorm your Commands will update the ModelLocator (usually a Singleton class) and your views will bind to the Model. The View basically says ‘give me the data’ and the reference to the Model is there in the View (in most cases).

Mate takes a different approach. With Mate your views are created with no reference to where the data is coming from. It provides public properties but should not provide a way to update them. Any internal logic should be done privately. Instead of a Singleton Model you create an EventMap and a Manager class to handle the injection of data into the views. Note the use of the word injection; this is the big mental shift. Your views are injected with the data they need but have no reference to where this data is coming from. This means your Views are completely decoupled from the Model and Controller … as it should be.

Now, how Mate does this is quite confusing at first. Especially problematic for a newbie is how it handles Class instantiation. In your EventMap you handle Events. These events may be requests for data from the back-end but may also be general requests from the views for some change in state. Within these EventHandler tags you can set properties on your Manager class or run methods on the Manager which will adjust its internal data ready for injectors to trigger changes in binding and inject the data from these Manager classes into the Views. Injectors are also setup in the EventMap and here’s where it gets confusing; the reference to the Manager class is not an instance of the class but the class itself …

<Injectors target=”{VideoScreen}” >
<PropertyInjector targetKey=”videoVO” source=”{AppManager}” sourceKey=”videoVO” />
</Injectors>

In this example, I want to inject my View (VideoScreen) with the videoVO property from the Manager (AppManager) classes videoVO property. Mate requires you to use the Class name as the target and will instantiate and cache the instance for you. The example above has now setup a binding between the AppManager and the VideoScreen class which is great … or is it? Originally I’d wanted to inject a property of the VO into my view and not the entire VO. What I wanted to do was this …

<Injectors target=”{VideoScreen}” >
<PropertyInjector targetKey=”source_url” source=”{AppManager}” sourceKey=”videoVO.source_url” />
</Injectors>

I like the idea of the Manager storing my VO classes but I want to inject specific properties from them into my views. To be completely decoupled it’s best that my views don’t reference VO classes but have very specific properties like the source_url property in my VideoScreen class. The only way I can think of doing this is to create the VO object within the EventMap and not in the AppManager. Like so …

<Injectors target=”{VideoScreen}” >
<PropertyInjector targetKey=”source_url” source=”{VideoVO}” sourceKey=”source_url” />
</Injectors>

… that would work. But then that got me thinking, what if I needed a whole bunch of VideoVO instances all stored in an ArrayCollection? I’d need to manage this logic within a Manager class but how would I manage the injection within the EventMap? My head is starting to hurt.

I know there must be some ingenious solution to these puzzles in my mind and I invite anyone who understands the framework a bit more than me to comment and offer me some insight. I can see the potential with this framework but at the moment these issues are preventing me from diving in.

More adventures in Mate soon no doubt.

[UPDATE]

Nahuel from ASFusion has posted on the forum about this here.
He pasted some code here.

Digg!

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in