//
//  UIGestureRecognizer+YSRACSignalSupport.m
//  ReactiveObjC
//
//  Created by Josh Vera on 5/5/13.
//  Copyright (c) 2013 GitHub. All rights reserved.
//

#import "UIGestureRecognizer+YSRACSignalSupport.h"
#import "YSRACEXTScope.h"
#import "NSObject+YSRACDeallocating.h"
#import "NSObject+YSRACDescription.h"
#import "YSRACCompoundDisposable.h"
#import "YSRACDisposable.h"
#import "YSRACSignal.h"
#import "YSRACSubscriber.h"

@implementation UIGestureRecognizer (YSRACSignalSupport)

- (YSRACSignal *)ysrac_gestureSignal {
	@weakify(self);

	return [[YSRACSignal
		createSignal:^(id<YSRACSubscriber> subscriber) {
			@strongify(self);

			[self addTarget:subscriber action:@selector(sendNext:)];
			[self.ysrac_deallocDisposable addDisposable:[YSRACDisposable disposableWithBlock:^{
				[subscriber sendCompleted];
			}]];

			return [YSRACDisposable disposableWithBlock:^{
				@strongify(self);
				[self removeTarget:subscriber action:@selector(sendNext:)];
			}];
		}]
		setNameWithFormat:@"%@ -ysrac_gestureSignal", YSRACDescription(self)];
}

@end
