PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: Oscar on September 19, 2007, 09:41:52



Title: Doesn't send the Model/Proxy an change Event?
Post by: Oscar on September 19, 2007, 09:41:52
Hello,

in a Classic MVC Architecture, the Model dispatch an Event to his listeners, when values in the Model are changed. 
It looks that in PureMVC, the Model or Proxy doesn't send such an Event.


Let's say, some value is changed in a Proxy/Model, and now I want, that other views react on this change.
How does it work in PureMVC?


Title: Re: Doesn't send the Model/Proxy an change Event?
Post by: puremvc on September 19, 2007, 10:06:16
When working with Flex and AIR, we have data structures (ArrayCollection/XMLListCollection) which already handle this communication for us.

Consider this scenario:
A Proxy holding an ArrayCollection of ValueObjects as its data property. A handle to the ArrayCollection is retrieved from the Proxy by a Mediator, who then sets it as the dataProvider for a DataGrid on its own View Component.

In this case, the ArrayCollection already has the ability to communicate the changes to any View Components that use it as a dataProvider. Therefore, there is often very little reason for us to duplicate that in PureMVC. For this reason, many Proxies end up being little more than bags of data, retrievable by name from the Model.

But that's not to say that you might not find the need to add these notifications from the Model. Aside from these built in Flex view updates, we may need for some business logic to be executed after the update as well.

Instead of the Proxy just allowing anyone to add something to its ArrayCollection, we may give it an addItem method, which adds the new item to the ArrayCollection, and then sends an itemAdded notification. Other parts of the View that need to react, may do so by expressing interest in this notification. Send deletedItem and changedItem notifications as well if need be. The Proxy then takes a more active role in managing the data it holds so that it can coordinate these changes with the rest of the application.

-=Cliff>


Title: Re: Doesn't send the Model/Proxy an change Event?
Post by: Oscar on September 19, 2007, 11:30:54
Thanks for your answer  :)

When working with Flex and AIR, we have data structures (ArrayCollection/XMLListCollection) which already handle this communication for us.


Is that only working in Flex and AIR?
In Flash and AS3 only Projects, you must make such notifications for the views manually with 'sendNotification(...)' and so on?


Title: Re: Doesn't send the Model/Proxy an change Event?
Post by: puremvc on September 19, 2007, 01:08:29
At the moment, yes. mx.collections.ArrayCollection is a Flex class. I recently I saw something about a Flash CS3 add-in that lets Flash use Flex components, but I don't know the details yet.

-=Cliff>


Title: Re: Doesn't send the Model/Proxy an change Event?
Post by: MMauny on October 06, 2008, 03:22:06
A useful idiom to employ in your concrete Proxy is an implicit getter that casts the Data Object to its actual type and gives it a meaningful name.

I think this idiom only don't apply on Java Port.
As say above, as3 data can send on change notifications.
In Java, the developper need to encapsulate the model modification.



Title: Re: Doesn't send the Model/Proxy an change Event?
Post by: puremvc on October 06, 2008, 06:21:05
True. In Java, you don't have the same sort of magic available in terms of the ArrayCollection updating view components. So the Proxy wouldn't expose the data as a property to be taken and set onto a view component, but would expose an explicit accessors, and would send notifications when changes occur.

You can do it this way in Flex as well, and some demos do. (For instance EmployeeAdmin's RoleProxy sends ADD_ROLE_RESULT when a role is added to a user).

-=Cliff>