Hello, nameless hero~
I encountered three problem about Notification of PureMVC, please have a look, Thanks for your time~
public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void
{
notifyObservers( new Notification( notificationName, body, type ) );
}
It's a method of Facade, and there will new a Notfication() instance when Facade call sendNotification each time.
Q1:Why don't make Notification to be singleton instance, as this:
//The method of Notification to configure Notification
public function setNotification(name:String, body:Object=null, type:String=null):INotification
{
this.name = name;
this.body = body;
this.type = type;
return this;
}
//some code section of Facade.
private var _notification:Notification = Notification.getInstance();
public function sendNotification( notificationName:String, body:Object=null, type:String=null ):void
{
notifyObservers( _notification.setNotification(notificationName, body, type));
}
public function notifyObservers(note:INotification):void
{
if(view != null) view.notifyObservers(note);
}
then goto the method notifyObservers of View:
public function notifyObservers(notification:INotification):void
{
if(observerMap[notification.getName()] != null){
var observers:Array = observerMap[notification.getName()] as Array;
for(var i:Number=0; i<observers.length; i++){
var observer:IObserver = observers as IObserver;
observer.notifyObserver(notification);
}
}
}
and then goto the mothod notifyObserver of Observer:
Q2: what's mean of [this.getNotifyMethod().apply(this.getNotifyContext(),[notification])], I feel a bit dizzy~
I think it means
public function notifyObserver(notification:INotification):void
{
//thisArg:* - The object to which the function is applied.
//argArray:* - An array whose elements are passed to the function as parameters.
this.getNotifyMethod().apply(this.getNotifyContext(),[notification]);
}
this is a common method in ApplicationFacade:
public function startup(app:Object):void
{
sendNotification( STARTUP, app );
}
Q3:Anybody could explain the Notification's inner chain of responsibility mechanism?
In my opinion:
First, Application call sendNotfication(notificationName:String, body:Object=null, type:String=null);
then, inner view call notifyObservers(note:INotification);
then, check out observerMap(In registerMediator method, according to mediator.listNotificationInterests() to registerObserver,
then add element into observersMap),to see if the notification exists, and call notifyObserver.
if(observerMap[notification.getName()] != null){
var observers:Array = observerMap[notification.getName()] as Array;
for(var i:Number=0; i<observers.length; i++){
var observer:IObserver = observers as IObserver;
observer.notifyObserver(notification);
}
}
then, .... I don't know how to say, the point is the mean of {this.getNotifyMethod().apply(this.getNotifyContext(),[notification])}, how it works, and then what happened?
Best regards~~
mani.