Merge pull request #377 from mrahmiao/develop
Adds two rx properties to Cocoa controls.
This commit is contained in:
commit
111bbfb5e3
|
|
@ -20,4 +20,15 @@ extension NSButton {
|
|||
public var rx_tap: ControlEvent<Void> {
|
||||
return rx_controlEvent
|
||||
}
|
||||
|
||||
/**
|
||||
Reactive wrapper for `state` property`.
|
||||
*/
|
||||
public var rx_state: ControlProperty<Int> {
|
||||
return rx_value(getter: { [weak self] in
|
||||
return self?.state ?? 0
|
||||
}, setter: { [weak self] state in
|
||||
self?.state = state
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -93,5 +93,23 @@ extension NSControl {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Bindable sink for `enabled` property.
|
||||
*/
|
||||
public var rx_enabled: AnyObserver<Bool> {
|
||||
return AnyObserver { [weak self] event in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
switch event {
|
||||
case .Next(let value):
|
||||
self?.enabled = value
|
||||
case .Error(let error):
|
||||
bindingErrorToInterface(error)
|
||||
break
|
||||
case .Completed:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)) }
|
||||
ensurePropertyDeallocated(createView, 0) { (view: NSButton) in view.rx_state }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// NSControl+RxTests.swift
|
||||
// Tests
|
||||
//
|
||||
// Created by mrahmiao on 1/1/16.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
import Cocoa
|
||||
import XCTest
|
||||
|
||||
class NSControlTests : RxTest {
|
||||
}
|
||||
|
||||
extension NSControlTests {
|
||||
func testEnabled_False() {
|
||||
let subject = NSButton(frame: CGRectMake(0, 0, 1, 1))
|
||||
Observable.just(false).subscribe(subject.rx_enabled).dispose()
|
||||
|
||||
XCTAssertTrue(subject.enabled == false)
|
||||
}
|
||||
|
||||
func testEnabled_True() {
|
||||
let subject = NSButton(frame: CGRectMake(0, 0, 1, 1))
|
||||
Observable.just(true).subscribe(subject.rx_enabled).dispose()
|
||||
|
||||
XCTAssertTrue(subject.enabled == true)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
4F0B0B231C36810E00BD0534 /* NSControl+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0B0B221C36810E00BD0534 /* NSControl+RxTests.swift */; };
|
||||
5E5D10BB1B48355200432B25 /* Control+RxTests+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5D10BA1B48355200432B25 /* Control+RxTests+UIKit.swift */; };
|
||||
C69B65001BA88FAC00A7FA73 /* ObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69B64FF1BA88FAC00A7FA73 /* ObserverTests.swift */; };
|
||||
C69B65011BA8957C00A7FA73 /* ObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69B64FF1BA88FAC00A7FA73 /* ObserverTests.swift */; };
|
||||
|
|
@ -212,6 +213,7 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
4F0B0B221C36810E00BD0534 /* NSControl+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSControl+RxTests.swift"; sourceTree = "<group>"; };
|
||||
5E5D10BA1B48355200432B25 /* Control+RxTests+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "Control+RxTests+UIKit.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
C69B64FF1BA88FAC00A7FA73 /* ObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObserverTests.swift; sourceTree = "<group>"; };
|
||||
C801EB591B97951100C4D8C4 /* Observable+CreationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "Observable+CreationTest.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
|
|
@ -417,6 +419,7 @@
|
|||
C8BCD3F81C14B901005F1280 /* UIView+RxTests.swift */,
|
||||
C8BCD3FD1C14BCAD005F1280 /* NSLayoutConstraint+RxTests.swift */,
|
||||
C8CF47651C1DA04700C3FA6E /* CLLocationManager+RxTests.swift */,
|
||||
4F0B0B221C36810E00BD0534 /* NSControl+RxTests.swift */,
|
||||
);
|
||||
path = RxCocoaTests;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
|
|
@ -765,6 +768,7 @@
|
|||
C8BCD3FC1C14B914005F1280 /* NSView+RxTests.swift in Sources */,
|
||||
C897EC3C1B10E000009C2CB0 /* BehaviorSubjectTest.swift in Sources */,
|
||||
C88BB8A51B07E64B0064D411 /* QueueTests.swift in Sources */,
|
||||
4F0B0B231C36810E00BD0534 /* NSControl+RxTests.swift in Sources */,
|
||||
C8E3812C1B2083C2008CDC33 /* PrimitiveMockObserver.swift in Sources */,
|
||||
C88BB8A61B07E64B0064D411 /* Observable+SingleTest.swift in Sources */,
|
||||
C897EC4B1B1123DA009C2CB0 /* Observable+MultipleTest+Zip.swift in Sources */,
|
||||
|
|
|
|||
Loading…
Reference in New Issue