Skip to content

Commit 107233d

Browse files
author
Cliff Hall
committed
2.0.4 Dissallowed re-registration of Mediators in View.registerMediator.
For more on this bug, see: http://forums.puremvc.org/index.php?topic=372 Modified View.notifyObservers to notify from a copy of the observer list rather than the actual observer list, which may change during the notification loop. For more on this bug, see: http://forums.puremvc.org/index.php?topic=490
1 parent 266ed87 commit 107233d

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/org/puremvc/as3/core/View.as

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,22 @@ package org.puremvc.as3.core
107107
public function notifyObservers( notification:INotification ) : void
108108
{
109109
if( observerMap[ notification.getName() ] != null ) {
110-
var observers:Array = observerMap[ notification.getName() ] as Array;
111-
for (var i:Number = 0; i < observers.length; i++) {
112-
var observer:IObserver = observers[ i ] as IObserver;
110+
111+
// Get a reference to the observers list for this notification name
112+
var observers_ref:Array = observerMap[ notification.getName() ] as Array;
113+
114+
// Copy observers from reference array to working array,
115+
// since the reference array may change during the notification loop
116+
var observers:Array = new Array();
117+
var observer:IObserver;
118+
for (var i:Number = 0; i < observers_ref.length; i++) {
119+
observer = observers_ref[ i ] as IObserver;
120+
observers.push( observer );
121+
}
122+
123+
// Notify Observers from the working array
124+
for (i = 0; i < observers.length; i++) {
125+
observer = observers[ i ] as IObserver;
113126
observer.notifyObserver( notification );
114127
}
115128
}
@@ -163,6 +176,9 @@ package org.puremvc.as3.core
163176
*/
164177
public function registerMediator( mediator:IMediator ) : void
165178
{
179+
// do not allow re-registration (you must to removeMediator fist)
180+
if ( mediatorMap[ mediator.getMediatorName() ] != null ) return;
181+
166182
// Register the Mediator for retrieval by name
167183
mediatorMap[ mediator.getMediatorName() ] = mediator;
168184

version.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
22
--------------------------------------------------------------------------
3-
Release Date: 03/17/08
3+
Release Date: 08/14/08
44
Platform: ActionScript 3 (Flash, Flex, AIR)
55
Version: 2
66
Revision: 0
7-
Minor: 3
7+
Minor: 4
88
Author: Cliff Hall <[email protected]>
99
License: Creative Commons Attribution 3.0 United States License
1010
--------------------------------------------------------------------------
11+
2.0.4 Dissallowed re-registration of Mediators in View.registerMediator.
12+
For more on this bug, see:
13+
http://forums.puremvc.org/index.php?topic=372
14+
Modified View.notifyObservers to notify from a copy of the
15+
observer list rather than the actual observer list, which may
16+
change during the notification loop. For more on this bug, see:
17+
http://forums.puremvc.org/index.php?topic=490
18+
1119
2.0.3 Added notifyObservers back to IFacade, where it is required
1220
if you are sending custom Notifications. No unit tests required.
1321

0 commit comments

Comments
 (0)