Monday, July 07, 2008

PureMVC: SendNotification vs. NotifyObservers

PureMVC has two ways to dispatch a Notification. A "note" for short, is like a Flex Event but that's another story. So what's the difference? The main difference is that sendNotifiaction builds the note and sends it at the same time. It's arguments are the same as Notification. notifyObservers is perfect for when you already have a notification constructed or you have a custom implementation of notification. notifyObservers(new Notification("SomeNotificationName"));

VS

sendNotification("SomeNotificationName") NotifyObservers can be called from the facade and other than the constructor argument, pretty much works the same way. sendNotification can be called from a proxy or mediator.I may have this wrong, but I don't think you can do sendNotification from a command, and I'm not sure exactly why. So if you need to dispatch an event from Command, I guess that's another use for facade.notifyObservers. You can send notifications from command, mediator, or proxy.

Labels: , , , , ,

Friday, June 27, 2008

PureMVC Argument

So me and the other people in my team got in a small argument over the proper use of PureMVC's mediators. We've read in various blogs that it is not a good practice to call a Proxy directly from a mediator. If you're going to call a proxy, it needs to be done from a command. In this particular case, we're asking for the proxy to refresh some data. That's it... one call. someProxy.refresh(). The refresh will send it's notification and our mediator will update. So one of my coworkers wanted to register a command that called someProxy.refresh() and then send a notification from the mediator. If there was some business logic that needed to happen, I'd be all for it! But there isn't, we're just refreshing an array collection. So someone please tell me why should I register a command to call a proxy in this case? And to further my point, the employee admin demo on PureMVC's official website does exactly what I'm describing in RolePanelMediator.as private function onAddRole( event:Event ):void { roleProxy.addRoleToUser( rolePanel.user, rolePanel.selectedRole ); } private function onRemoveRole( event:Event ):void { roleProxy.removeRoleFromUser( rolePanel.user, rolePanel.selectedRole ); } I am not a very stubborn person. if someone can make a good point for why I shouldn't do it this way, then I'll change my ways. I promise.

Labels: , , , , , ,

Feed (RSS/Atom)

Contact Me

Don't put anything here: