Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Proxies and Data Binding  (Read 7495 times)
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« on: January 04, 2008, 02:25:51 »

I have a couple of things I am trying to get my head around.

My first pureMVC application had 3 proxies. One of them I named DataProxy, and it was the place that held ALL of my remote services. That was fine, for awhile, but then it got seriously complex and hard to find anything I wanted. So now I am dividing up each model (dbase table) into it's own proxy class. How do you guys do this? One proxy to rule them all, individual proxies, or a mix?

I also had a question regarding data binding. This is Flex specific. My data is updated every couple of minutes from the server. I use the [Bindable] metatag, but it doesn't seem to have an effect and you can't use it on the data object or getData() anyway. What is the preferred method for updating a datagrid, or any other container with a dataProvider property?
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Rhysyngsun
Courseware Beta
Sr. Member
***
Posts: 51

Nathan Levesque

 - rhysyngsun@gmail.com  - rhysyngsun
View Profile WWW Email
« Reply #1 on: January 04, 2008, 04:13:54 »

How is your database setup? Is it an object-relational database? It it is, I would have a VO to represent a data row from each table, then have a single Proxy handle the relationships between the related VO's. However, if you happen to have other tables in the same database that don't relate to these tables, they should be in another proxy. you should basically separate things by what type of service the Proxy is offering. Less is almost always more.

As far as the [Bindable] tag, you can only use it on either object variables or explicit get/set function pair. Since getData is just a regular function the[Bindable] tag won't work on it. At any rate, in PureMVC you want to do it a little differently.


This basic principle of all this is Proxy->Notification->Mediator->View->Datagrid. Hope that helps:

First you would have your concrete Proxy send a notification that the data has changed by passing the data in the body of the notification. In your Mediator's listNotificationInterests() function you have that particular notification listed in the returned array. Then in the Mediator's handleNotifications, you have a switch statement that switches through the values of note.getName(). when you handle the case that is your particular notification you simply get the data note.getBody(), cast it to the appropriate data type, and then assign this to a public property in your view.

This public property should be [bindable], which you then bind to the dataProvider property in your datagrid. When you set the public property through your Mediator, Flex detects this, and tells the datagrid to update because it is bound to it.

Logged

Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #2 on: January 04, 2008, 07:50:19 »

Thanks Nathan.

I'm using Django with mySQL as my backend. They are very relational with lots of foreign keys. I'm having trouble visualizing the setup you suggest. Could I talk you into going into more detail? Here's a bit of the domain I am dealing with:

Case
   id
   client
   some_date

Task
   id
   case_id
   due_date
   assigned_to_id

Person
   id
   first_name
   last_name

Hmm, perhaps my problem was that I had the dataProvider in the mediator instead of as a public property in the view compoenent. That makes sense, and would explain why my bindings weren't working.

Cheers,

Joel
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Pages: [1]
Print