PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: riafan on May 17, 2008, 06:57:43



Title: Minor View change *suggestion*
Post by: riafan 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?


Title: Re: Minor View change *suggestion*
Post by: puremvc 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>


Title: Re: Minor View change *suggestion*
Post by: riafan 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).



Title: Re: Minor View change *suggestion*
Post by: puremvc 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>


Title: Re: Minor View change *suggestion*
Post by: riafan 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!!