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: Minor View change *suggestion*  (Read 9731 times)
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« on: May 17, 2008, 06:57:43 »

I've been cleaning up my code (hoping to post it soon) on dynamically loaded modules. 

First off, I realize the View can be sub-classed easily - this is just a suggestion to avoid the need of doing so.

I came across the following function in the View class

:

public function removeObserver( notificationName:String, notifyContext:Object ):void
{
// the observer list for the notification under inspection
var observers:Array = observerMap[ notificationName ] as Array;

// find the observer for the notifyContext
for ( var i:int=0; i<observers.length; i++ )
{
if ( Observer(observers[i]).compareNotifyContext( notifyContext ) == true ) {
// there can only be one Observer for a given notifyContext
// in any given Observer list, so remove it and break
observers.splice(i,1);
break;
}
}

// Also, when a Notification's Observer list length falls to
// zero, delete the notification key from the observer map
if ( observers.length == 0 ) {
delete observerMap[ notificationName ];
}
}


This works great when the mediator has a static lists of interests.  However when that list is dynamic some problems can arise. 

My request is for the addition of a simple check that

:
var observers:Array = observerMap[ notificationName ] as Array;

didn't return null...

:

if(!observers)
   return;


What do you think?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 18, 2008, 07:24:59 »

I'm a little concerned. When and how are you embuing a Mediator with a dynamic list of interests?

-=Cliff>
Logged
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« Reply #2 on: May 19, 2008, 09:35:57 »

Cliff,
  I should have let the dust settle before posting.  Please disregard the request :)

(This was to support the change in a dynamically loaded modules "notification Interests" over time - I've settled for a much cleaner approach).

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: May 19, 2008, 10:43:19 »

Ah, gotcha, this would be the approach you ended up with in your recent post http://dluminosity.com/blog/2008/05/19/dynamic-flex-modules-with-puremvc/

-=Cliff>
Logged
riafan
Courseware Beta
Jr. Member
***
Posts: 19


View Profile WWW Email
« Reply #4 on: May 19, 2008, 11:25:04 »

Yes, I settled on inbound / outbound notification mappings being defined statically.  This turned out to be a better approach.

thanks again!!

Logged
Pages: [1]
Print