PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: amerineni on February 17, 2010, 09:22:36

Title: Send/listen notifications between Mediators in a viewstack with many children
Post by: amerineni on February 17, 2010, 09:22:36

    Guys, we are facing the following issue for transfering the data between mediators through notifications. 
                        Our app mainly consists of a viewstack which has 20 different views. Views are switched by the events dispatched by the Menu item. We are registering the  mediators on the CREATION_COMPLETE event of each child. We got some scenarios, where we need to navigate  from one view to another view(target view) by passing some information.  We are doing this by sending a notification from the existing view and handling it in the application mediator(where it has access to the viewstack). There in the handler I am temporarily storing the data sent, dispatching an event to set the viewstack index to the target view and listening for the SHOW event of the target  view(because by this time the view has not been created, so façade doesn’t know the interests of the target view). In the handler for this SHOW event I am dispatching notification attaching the temporarily stored data and handling this notification in the target view mediator.

Currently we need to circle all the way in order to send data from one viewstack view to another. Can you suggest any better suggestion for doing this?

any help will be appreciated.


Title: Re: Send/listen notifications between Mediators in a viewstack with many children
Post by: puremvc on February 17, 2010, 10:30:07
You can encapsulate this data transfer in the custom viewstack component (or the component that contains it.

Have the custom ViewStack component have a bindable property called something like transferData. Then when one view needs to toss up some data to be transferred to the next view, have it send a custom event that the custom viewstack listens for, takes the data from and stores in its transferData property. Then let all the view stack children bind to this transferData property.

You might have to set or clear it on changes, but ultimately this sounds like a job for the component's internal wiring.

People often bash PureMVC because isn't doesn't use binding, and true, it doesn't. That's because binding is really best used inside a view component to move data and state between sub components in the view hierarchy. This is the perfect place for it.