mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-18 00:21:27 +00:00
+ (BOOL)automaticallyNotifiesObserversOf<Key> support.
This commit is contained in:
@@ -71,6 +71,12 @@
|
||||
|
||||
+ (BOOL)automaticallyNotifiesObserversForKey:(CPString)aKey
|
||||
{
|
||||
var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1),
|
||||
selector = "automaticallyNotifiesObserversOf" + capitalizedKey;
|
||||
|
||||
if ([[self class] respondsToSelector:selector])
|
||||
return objj_msgSend([self class], selector);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@@ -193,11 +193,37 @@
|
||||
notSame:class_getInstanceMethod([object class], removeSelector)];
|
||||
}
|
||||
|
||||
- (void)testAutomaticallyNotifiesObserversOf
|
||||
{
|
||||
var test = [ObservingTester new];
|
||||
|
||||
[test addObserver:self forKeyPath:@"cheese" options:0 context:nil];
|
||||
[test addObserver:self forKeyPath:@"astronaut" options:0 context:nil];
|
||||
|
||||
// Cheese shouldn't have been affected.
|
||||
[test setCheese:@"changed cheese"];
|
||||
[self assert:@"cheese" equals:_lastKeyPath]
|
||||
[self assert:test equals:_lastObject];
|
||||
|
||||
// Cheese shouldn't have been affected.
|
||||
[test setAstronaut:@"Armstrong"];
|
||||
// Nothing should have been observed because we don't automatically notify
|
||||
// and we didn't call will/didChange.
|
||||
[self assert:@"cheese" equals:_lastKeyPath message:"no observation when automatically notifies is off"];
|
||||
[self assert:test equals:_lastObject];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ObservingTester : CPObject
|
||||
{
|
||||
id cheese;
|
||||
id astronaut @accessors;
|
||||
}
|
||||
|
||||
+ (BOOL)automaticallyNotifiesObserversOfAstronaut
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (id)testerWithCheese:(id)aCheese
|
||||
|
||||
Reference in New Issue
Block a user