PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: tvde on October 20, 2008, 02:44:39



Title: How to handle multiple views of the same type?
Post by: tvde on October 20, 2008, 02:44:39
I'm struggling with the fact that I have multiple views of the same type in a tab navigator. The problem starts when calling proxy methods from the mediators attached to these views. The results of these methods are communicated through notifications. The problem is that ALL mediators get these notifications although only the mediator that called the proxy medthod is interested in the result. Is there some framework support for this or do I have to do my own plumbing?


Title: Re: How to handle multiple views of the same type?
Post by: Joel Hooks on October 20, 2008, 07:27:49
You'll have to pass around some sort of identifier (the mediators name?), so I guess that is a yes to your plumbing question.


Title: Re: How to handle multiple views of the same type?
Post by: Jason MacDonald on October 20, 2008, 10:21:30
send the notification using the getMediatorName() as the note.setType(). Then in the response check the note.getType() against the Mediator.getMediatorName();

:
// sending note from a mediator
facade.sendNotification(ApplicationFacade.MY_NOTE, 'my body here', this.getMediatorName());

// when it comes back
case ApplicationFacade.MY_NOTE_RECIEVED:
       if(note.getType() == this.getMediatorName()) {
            // process response here
       }

[code]
[/code]


Title: Re: How to handle multiple views of the same type?
Post by: tvde on October 20, 2008, 12:28:19
Thanks for the feedback! I took the same road like Joel proposed (after making sure the mediator name is unique through createUID). I don't understand however that (Pure)MVC doesn't have support for something essential like this out of the box  ???


Title: Re: How to handle multiple views of the same type?
Post by: Joel Hooks on October 20, 2008, 03:16:21
Thanks for the feedback! I took the same road like Joel proposed (after making sure the mediator name is unique through createUID). I don't understand however that (Pure)MVC doesn't have support for something essential like this out of the box  ???

My guess is that the framework is supposed to be 'as simple as possible, but no simpler' and this sort of solution is one that will vary from project to project. Using the Notification body and/or type parameters is effective for this sort of thing, so really it does support it out of box.

If you have a good way to plumb something up, you might consider writing a utility to do so. I'd love to check it out. I'm running through solutions in my head, but I get stuck at the way I've always done it (as described in my other post).

Cheers


Title: Re: How to handle multiple views of the same type?
Post by: rdewolff on November 26, 2008, 11:02:40
You could load and unload mediators depending on your needs too.