We weren't actually keeping track of replaced methods, and thus were replacing every time you call addObserver:

This commit is contained in:
Ross Boucher committed 2011-02-25 17:59:54 -08:00
1 parent 3ebb432d3f
commit 6435372fd9
2 files changed
+26

No files matched your search

+2
View File
@@ -295,6 +295,8 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti
if ([_replacedKeys containsObject:aKey] || ![_nativeClass automaticallyNotifiesObserversForKey:aKey])
return;
[_replacedKeys addObject:aKey];
var theClass = _nativeClass,
KVOClass = _targetObject.isa,
capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1);
+24
View File
@@ -440,6 +440,30 @@
[self assert:observationCount equals:3];
}
- (void)testSettersReplacedOnce
{
var bob = [[PersonTester alloc] init],
betty = [CPObject new];
[bob addObserver:self forKeyPath:@"name" options:nil context:"testSettersReplacedOnce"];
var oldImp = class_getMethodImplementation(bob.isa, @selector(setName:));
[bob removeObserver:self forKeyPath:@"name"];
[bob addObserver:self forKeyPath:@"name" options:nil context:"testSettersReplacedOnce"];
var newImp = class_getMethodImplementation(bob.isa, @selector(setName:));
[self assertTrue:newImp === oldImp];
[bob addObserver:betty forKeyPath:@"name" options:nil context:"testSettersReplacedOnce"];
var newImp = class_getMethodImplementation(bob.isa, @selector(setName:));
[self assertTrue:newImp === oldImp];
}
- (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)changes context:(id)aContext
{
var oldValue = [changes objectForKey:CPKeyValueChangeOldKey],