mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-27 02:25:36 +00:00
We weren't actually keeping track of replaced methods, and thus were replacing every time you call addObserver:
This commit is contained in:
1 parent
3ebb432d3f
commit
6435372fd9
2 files changed
+26
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in new issue
Block a user