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: [EDGE CASE / ANTIPATTERN] Remove observer error  (Read 8703 times)
mrichard1
Newbie
*
Posts: 5


View Profile Email
« on: August 15, 2008, 12:18:14 »

Hi,

I report to you a bug when I try to remove a mediator, the observers result is null in the View class and removeObserver method.

This is normal in my case that the return value is null because I update dynamically the listNotificationInterests in the mediator and one of these was not registered. (I remove and insert it to update this list )


I propose a solution to put in the removeObserver method ,

if( !observers ){ //correct null error
   return ;
}

Thanks.

Best regards,
Marc
« Last Edit: August 15, 2009, 08:09:39 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 15, 2008, 05:09:33 »

Dynamically messing with the observer lists is not a best practice. The framework maintains those lists. This is why Mediators are interrogated for their interests at registration time.

If you change the interests of a Mediator dynamically, then you MUST have its listNotificationInterests method return the *current* interests (NOT the initial interests) at removal time. If you do this, your problem will not occur.

If ths had come in yesterday, I would've included it in the 2.0.4 release.

Filed under edge-case anti-pattern with workaround for now.

-=Cliff>
Logged
Pages: [1]
Print