mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-28 09:22:03 +00:00
better fix for long key paths
The previous fix for issue #967 would only work if there was only one object observing a compound key path like selection.customer.name.
This commit is contained in:
1 parent
ca60e50128
commit
1e85a054ac
1 file changed
+8
-4
@@ -509,7 +509,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
||||
CPDictionary _cachedValues;
|
||||
CPArray _observationProxies;
|
||||
|
||||
_CPObservableArray _observedObjects;
|
||||
Object _observedObjectsByKeyPath;
|
||||
}
|
||||
|
||||
- (id)initWithController:(id)aController
|
||||
@@ -519,6 +519,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
||||
_cachedValues = [CPDictionary dictionary];
|
||||
_observationProxies = [CPArray array];
|
||||
_controller = aController;
|
||||
_observedObjectsByKeyPath = {};
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -614,8 +615,9 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
||||
|
||||
// We keep are reference to the observed objects
|
||||
// because the removeObserver: will be called after the selection changes
|
||||
_observedObjects = [_controller selectedObjects];
|
||||
[_observedObjects addObserver:proxy forKeyPath:aKeyPath options:options context:context];
|
||||
var observedObjects = [_controller selectedObjects];
|
||||
_observedObjectsByKeyPath[aKeyPath] = observedObjects;
|
||||
[observedObjects addObserver:proxy forKeyPath:aKeyPath options:options context:context];
|
||||
}
|
||||
|
||||
- (void)removeObserver:(id)anObject forKeyPath:(CPString)aKeyPath
|
||||
@@ -623,7 +625,9 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
||||
var proxy = [[_CPObservationProxy alloc] initWithKeyPath:aKeyPath observer:anObject object:self],
|
||||
index = [_observationProxies indexOfObject:proxy];
|
||||
|
||||
[_observedObjects removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath];
|
||||
var observedObjects = _observedObjectsByKeyPath[aKeyPath];
|
||||
[observedObjects removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath];
|
||||
|
||||
[_observationProxies removeObjectAtIndex:index];
|
||||
|
||||
_observedObjects = nil;
|
||||
|
||||
Reference in new issue
Block a user