//
//  NSNotificationCenter+YSRACSupport.m
//  ReactiveObjC
//
//  Created by Josh Abernathy on 5/10/12.
//  Copyright (c) 2012 GitHub. All rights reserved.
//

#import "NSNotificationCenter+YSRACSupport.h"
#import "YSRACEXTScope.h"
#import "YSRACSignal.h"
#import "YSRACSubscriber.h"
#import "YSRACDisposable.h"

@implementation NSNotificationCenter (YSRACSupport)

- (YSRACSignal *)ysrac_addObserverForName:(NSString *)notificationName object:(id)object {
	@unsafeify(object);
	return [[YSRACSignal createSignal:^(id<YSRACSubscriber> subscriber) {
		@strongify(object);
		id observer = [self addObserverForName:notificationName object:object queue:nil usingBlock:^(NSNotification *note) {
			[subscriber sendNext:note];
		}];

		return [YSRACDisposable disposableWithBlock:^{
			[self removeObserver:observer];
		}];
	}] setNameWithFormat:@"-ysrac_addObserverForName: %@ object: <%@: %p>", notificationName, [object class], object];
}

@end
