From 96aef6e47a5f8e49cddab84d0e0efb2d1f9142d8 Mon Sep 17 00:00:00 2001 From: mrahmiao Date: Fri, 1 Jan 2016 17:30:34 +0800 Subject: [PATCH] Adds `rx_state` to `NSButton`. --- RxCocoa/OSX/NSButton+Rx.swift | 11 +++++++++++ Tests/RxCocoaTests/Control+RxTests+Cocoa.swift | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/RxCocoa/OSX/NSButton+Rx.swift b/RxCocoa/OSX/NSButton+Rx.swift index 460baef2..0c6e5f6c 100644 --- a/RxCocoa/OSX/NSButton+Rx.swift +++ b/RxCocoa/OSX/NSButton+Rx.swift @@ -20,4 +20,15 @@ extension NSButton { public var rx_tap: ControlEvent { return rx_controlEvent } + + /** + Reactive wrapper for `state` property`. + */ + public var rx_state: ControlProperty { + return rx_value(getter: { [weak self] in + return self?.state ?? 0 + }, setter: { [weak self] state in + self?.state = state + }) + } } \ No newline at end of file diff --git a/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift b/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift index a81fd3d3..90555276 100644 --- a/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift +++ b/Tests/RxCocoaTests/Control+RxTests+Cocoa.swift @@ -41,4 +41,9 @@ extension ControlTests { let createView: () -> NSButton = { NSButton(frame: CGRectMake(0, 0, 1, 1)) } ensureEventDeallocated(createView) { (view: NSButton) in view.rx_tap } } + + func testButton_StateCompletesOnDealloc() { + let createView: () -> NSButton = { NSButton(frame: CGRectMake(0, 0, 1, 1)) } + ensureEventDeallocated(createView) { (view: NSButton) in view.rx_state } + } } \ No newline at end of file