puremvc-as3-standard-framework icon indicating copy to clipboard operation
puremvc-as3-standard-framework copied to clipboard

Fixed notification loop in View.notifyObservers for cases if some Observers has been removed during the notification loop.

Open alphashooter opened this issue 10 years ago • 1 comments

alphashooter avatar Sep 10 '15 09:09 alphashooter

notifyObservers() method may fail if any Observer to be notified next is removed during the notification loop. E.g. if you register two Mediators for the same notification and the first one removes the second during notification handling, the second Mediator will be notified anyway, and moreover notified after onRemove() method called. Iterating through a copy of observers_ ref prevents array shifting if you remove any Observer which is already notified (commit 107233d2c23e44a2be96f4fefa4affc74f3afde5); but no checks has been added for the case if you remove any Observer to be notified next. For this case observers_ref holds reference to the source array of Observers; so if any Observer is removed, observers_ref.indexOf(observer) has result -1 and loop continues to the next iteration.

alphashooter avatar Sep 14 '15 20:09 alphashooter