mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
fail more gracefully when attempting to remove the same observer twice
Before this commit we would fail gracefully for single keys. For key paths an application would crash because we would try to get the forwarder property of an undefined object. This commit makes sure we don't attempt any removal and logs a warning (just like Cocoa) about the attempt to remove an unregistered observer.
This commit is contained in:
@@ -678,6 +678,14 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti
|
||||
{
|
||||
var observers = _observersForKey[aPath];
|
||||
|
||||
if (!observers)
|
||||
{
|
||||
CPLog.warn(@"Cannot remove an observer %@ for the key path \"%@\" from %@ because it is not registered as an observer.",
|
||||
_targetObject, aPath, anObserver);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (aPath.indexOf('.') != CPNotFound)
|
||||
{
|
||||
var forwarder = [observers objectForKey:[anObserver UID]].forwarder;
|
||||
|
||||
Reference in New Issue
Block a user