search
top
Currently Browsing: Flex

PureMVC Easy Model Calls

Something I’ve tried and liked recently, using MXML is binding the view to the model. makes life very clean and easy. However, there’s the issue of calling a request, listening for a response, getting the data and then pointing it at the view for the view to handle, or even more cumbersome, listening to it via the Mediator and then populating views that way.

I’ve found a way I like better. It may not be new, but it’s clean, simple, and easy to understand.

For example, I want to do a search for the latest images from a webservice. Well my ImagesProxy.instance.search(‘latest images’), can call a search. Great! But I still got to hook up to it. So..

[code]

ImagesProxy.instance.search(type:String, limit:int=20):ArrayCollection

[/code]

The ArrayCollection is the dataProvider for your view, that gets populated with the results.

The great thing about this, is you recieve the reference to the data. In MXML, the views or specifically components can bind to the data models meaning..

you can write code like this :

[code]

<s:DataGroup dataProvider="{ImageProxy.instance.search('latest images', 20)}" itemRenderer="ImageItemRenderer">
<s:layout>
<s:HorizontalLayout horizontalAlign="left"  gap="10" columnWidth="155"/>
</s:layout>
</s:DataGroup>

[code]

Genius.. one line of code :)

top