PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: rbhadra on May 12, 2008, 07:05:06



Title: how to use sendNotification inside Model
Post by: rbhadra on May 12, 2008, 07:05:06
Hi,
This is the first time I am using pureMVC framework.I am creating an small application using Flex.
There are bunch of question I want to ask.

1) If there is a class which acts a Model. This class contains methods as add(),remove(),update() etc..When any of these methods are called I want to dispatch or use sendNotification() method. So what class should I extend. Notifier or proxy because this class will only manipulate other model class.And also which interafaces I need to implement

2) How can I manipulate one of the model class data from another model class..If a model class is sending any notification either by extending proxy or notifier(refer question 1) how do I use handleNotification() method inside Model.This is quite confusing for me.

From the diagram I understand that proxies cant communicate with each other.They can interact with each other via Commands.Can you help me out how do I implement it.Please help.Please provide me the solution with the help of a small snippet.

3) Is it necessary that a class extending a Proxy should implement load() function. I want to use sendNotification function and also handleNotification in 2 model classes.Lets say a ConfigProxy is loaded and DataProxy are 2 model classes.
ConfigProxy sends notification sendNotification(Add_Element) and DataProxy should listen for this notification. How can I implement that.At the same time DataProxy should be handling the notification sent using handleNotifcation() method...Am I doing anything wrong here..Please let me know.

Thanks


Title: Re: how to use sendNotification inside Model
Post by: puremvc on May 20, 2008, 08:15:05
1) Proxy. Implement or extend, its up to you.

2) Proxies have access to the facade. Do facade.retrieveProxy(proxyName).

3) IProxy doesn't require a load method. And Proxies don't have handleNotification because it would be too tempting to make them dependent the view implementation and the messages it defines and sends.

I would suggest taking half a day or so and reading the Best Practices doc. You'll find it's a much easier way to learn :)

-=Cliff>


Title: Re: how to use sendNotification inside Model
Post by: rbhadra on May 22, 2008, 03:25:42
In the constructor of ModelPrepCommand I have included the line facade.registerProxy(new MyProxy()); where MyProxy is extending Proxy as per your suggestion. But when I dont write a load function inside MyProxy class it throws an error into the loadResources function of StartupMonitorProxy class.So I have to fake it

public function load():void
{
  this.data = new Object();
  this.startupMonitorProxy.resourceComplete(MyProxy.NAME);
}

Please help me on this.


Title: Re: how to use sendNotification inside Model
Post by: puremvc on May 22, 2008, 09:00:36
Ah, you failed to mention you were using the StartupManager utility. That's where the requirement for a load method is coming from.

In order to better understand that utility and how to use it in your application, I would suggest going to the StartupManager Utility page on and checking out the recently posted tutorial 'Getting Started with StartupManager'

-=Cliff>


Title: Re: how to use sendNotification inside Model
Post by: harmanjd on June 12, 2008, 09:07:59
Also - you won't need a load method if you don't register the Proxy with the startup monitor.  You only need to register proxies with the startupmonitor that need to load resources at startup.