Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: how to use sendNotification inside Model  (Read 8192 times)
rbhadra
Newbie
*
Posts: 4


View Profile Email
« 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
« Last Edit: May 12, 2008, 07:15:16 by rbhadra » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
rbhadra
Newbie
*
Posts: 4


View Profile Email
« Reply #2 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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>
Logged
harmanjd
Newbie
*
Posts: 5


View Profile Email
« Reply #4 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.
Logged
Pages: [1]
Print