From 9394b50a5ae4123bebbcbc8b1662b7658ed5a4b8 Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 09:27:28 +0300 Subject: [PATCH 1/6] add completed and started signals to Action --- Source/Action.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/Action.swift b/Source/Action.swift index 34219e35c6..47e5c9cc1f 100644 --- a/Source/Action.swift +++ b/Source/Action.swift @@ -14,6 +14,26 @@ extension Action { public static var rex_disabled: Action { return Action(enabledIf: ConstantProperty(false)) { _ in .empty } } + + /// Whether the action execution was completed succesfully. + public var completed: Signal { + return events + .filter { event in + if case .Completed = event { + return true + } else { + return false + } + } + .map { _ in } + } + + /// Whether the action execution was started. + public var started: Signal { + return self.executing.signal + .filter { $0 } + .map { _ in } + } } extension CocoaAction { From 8a949b1e0688b016a97f32faf732656618d25cdf Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 09:50:15 +0300 Subject: [PATCH 2/6] add `rex_` prefix to new properties --- Source/Action.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Action.swift b/Source/Action.swift index 47e5c9cc1f..ab2cfb6e05 100644 --- a/Source/Action.swift +++ b/Source/Action.swift @@ -16,7 +16,7 @@ extension Action { } /// Whether the action execution was completed succesfully. - public var completed: Signal { + public var rex_completed: Signal { return events .filter { event in if case .Completed = event { @@ -29,7 +29,7 @@ extension Action { } /// Whether the action execution was started. - public var started: Signal { + public var rex_started: Signal { return self.executing.signal .filter { $0 } .map { _ in } From 8f4bdfbf8db29ea9eeae7652359eff9d7e1b19dc Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 13:15:18 +0300 Subject: [PATCH 3/6] fix typo --- Source/Action.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Action.swift b/Source/Action.swift index ab2cfb6e05..a4f88af751 100644 --- a/Source/Action.swift +++ b/Source/Action.swift @@ -15,7 +15,7 @@ extension Action { return Action(enabledIf: ConstantProperty(false)) { _ in .empty } } - /// Whether the action execution was completed succesfully. + /// Whether the action execution was completed successfully. public var rex_completed: Signal { return events .filter { event in From ef93173ad76da2f623e39042493fc5fde044fcb7 Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 15:33:55 +0300 Subject: [PATCH 4/6] add Action tests --- Rex.xcodeproj/project.pbxproj | 8 ++++ Tests/ActionTests.swift | 71 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 Tests/ActionTests.swift diff --git a/Rex.xcodeproj/project.pbxproj b/Rex.xcodeproj/project.pbxproj index d2a7aeb041..9c28d26840 100644 --- a/Rex.xcodeproj/project.pbxproj +++ b/Rex.xcodeproj/project.pbxproj @@ -44,6 +44,9 @@ C7945F141CC1DFBE00DC9E37 /* UIViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7945F121CC1DFB400DC9E37 /* UIViewControllerTests.swift */; }; C7DCE2B41CB3C89A001217D8 /* UITextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DCE2B21CB3C872001217D8 /* UITextView.swift */; }; C7DCE2B71CB3C9D6001217D8 /* UITextViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7DCE2B51CB3C9C1001217D8 /* UITextViewTests.swift */; }; + CC02C18A1CCA704E0025CC04 /* ActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC02C1881CCA704C0025CC04 /* ActionTests.swift */; }; + CC02C18B1CCA704F0025CC04 /* ActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC02C1881CCA704C0025CC04 /* ActionTests.swift */; }; + CC02C18C1CCA704F0025CC04 /* ActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC02C1881CCA704C0025CC04 /* ActionTests.swift */; }; D8003E941AFEC3D400D7D3C5 /* Rex.h in Headers */ = {isa = PBXBuildFile; fileRef = D8003E931AFEC3D400D7D3C5 /* Rex.h */; settings = {ATTRIBUTES = (Public, ); }; }; D8003EB41AFEC6B000D7D3C5 /* ReactiveCocoa.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = D8003EAD1AFEC68A00D7D3C5 /* ReactiveCocoa.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D8003EB51AFEC6B000D7D3C5 /* Result.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = D8003EAE1AFEC68A00D7D3C5 /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -222,6 +225,7 @@ C7945F121CC1DFB400DC9E37 /* UIViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerTests.swift; sourceTree = ""; }; C7DCE2B21CB3C872001217D8 /* UITextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextView.swift; sourceTree = ""; }; C7DCE2B51CB3C9C1001217D8 /* UITextViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextViewTests.swift; sourceTree = ""; }; + CC02C1881CCA704C0025CC04 /* ActionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionTests.swift; sourceTree = ""; }; D8003E921AFEC3D400D7D3C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; D8003E931AFEC3D400D7D3C5 /* Rex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Rex.h; sourceTree = ""; }; D8003E9F1AFEC3D400D7D3C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -371,6 +375,7 @@ D8003E9D1AFEC3D400D7D3C5 /* Tests */ = { isa = PBXGroup; children = ( + CC02C1881CCA704C0025CC04 /* ActionTests.swift */, D8A454081BD2772700C9E790 /* PropertyTests.swift */, D8003EBE1AFED2F800D7D3C5 /* SignalTests.swift */, D8003EC01AFED30100D7D3C5 /* SignalProducerTests.swift */, @@ -803,6 +808,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CC02C18A1CCA704E0025CC04 /* ActionTests.swift in Sources */, D8F0974A1B17F5E1002E15BA /* NSObjectTests.swift in Sources */, D8003EC21AFED30F00D7D3C5 /* SignalTests.swift in Sources */, D8003EC31AFED30F00D7D3C5 /* SignalProducerTests.swift in Sources */, @@ -846,6 +852,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CC02C18B1CCA704F0025CC04 /* ActionTests.swift in Sources */, 7DC325801CC6FD2100746D88 /* UITableViewHeaderFooterViewTests.swift in Sources */, 8289A2E11BD7EF1F0097FB60 /* UIImageViewTests.swift in Sources */, D8F0974B1B17F5E2002E15BA /* NSObjectTests.swift in Sources */, @@ -920,6 +927,7 @@ D8715DDE1C211637005F4191 /* SignalProducerTests.swift in Sources */, D8715DE11C211643005F4191 /* UIButtonTests.swift in Sources */, D8715DE21C211643005F4191 /* UIControlTests.swift in Sources */, + CC02C18C1CCA704F0025CC04 /* ActionTests.swift in Sources */, D8715DDF1C21163B005F4191 /* NSObjectTests.swift in Sources */, 7DC3257E1CC6FD1C00746D88 /* UITableViewCellTests.swift in Sources */, D8715DDC1C211637005F4191 /* PropertyTests.swift in Sources */, diff --git a/Tests/ActionTests.swift b/Tests/ActionTests.swift new file mode 100644 index 0000000000..7df33d6f84 --- /dev/null +++ b/Tests/ActionTests.swift @@ -0,0 +1,71 @@ +// +// ActionTests.swift +// Rex +// +// Created by Ilya Laryionau on 4/20/16. +// Copyright © 2016 Neil Pankey. All rights reserved. +// + +@testable import Rex +import ReactiveCocoa +import XCTest +import enum Result.NoError + +final class ActionTests: XCTestCase { + + enum TestError: ErrorType { + case Unknown + } + + func testStarted() { + let action = Action { .empty } + + var started = false + action + .rex_started + .observeNext { started = true } + + action + .apply() + .start() + + XCTAssertTrue(started) + } + + func testCompleted() { + let (producer, sink) = SignalProducer.buffer(Int.max) + let action = Action { producer } + + var completed = false + action + .rex_completed + .observeNext { completed = true } + + action + .apply() + .start() + + sink.sendNext(1) + XCTAssertFalse(completed) + + sink.sendCompleted() + XCTAssertTrue(completed) + } + + func testCompletedOnFailed() { + let (producer, sink) = SignalProducer.buffer(Int.max) + let action = Action { producer } + + var completed = false + action + .rex_completed + .observeNext { completed = true } + + action + .apply() + .start() + + sink.sendFailed(.Unknown) + XCTAssertFalse(completed) + } +} From ba976b0fe36aa80ebfa4b2eaf31b9127e2285a58 Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 15:34:56 +0300 Subject: [PATCH 5/6] change the order of properties in source file --- Source/Action.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Action.swift b/Source/Action.swift index a4f88af751..f664809ce5 100644 --- a/Source/Action.swift +++ b/Source/Action.swift @@ -14,6 +14,13 @@ extension Action { public static var rex_disabled: Action { return Action(enabledIf: ConstantProperty(false)) { _ in .empty } } + + /// Whether the action execution was started. + public var rex_started: Signal { + return self.executing.signal + .filter { $0 } + .map { _ in } + } /// Whether the action execution was completed successfully. public var rex_completed: Signal { @@ -27,13 +34,6 @@ extension Action { } .map { _ in } } - - /// Whether the action execution was started. - public var rex_started: Signal { - return self.executing.signal - .filter { $0 } - .map { _ in } - } } extension CocoaAction { From b3b6e296d70da0a3a1a54d241edace1524b01ddb Mon Sep 17 00:00:00 2001 From: Ilya Laryionau Date: Wed, 20 Apr 2016 20:24:17 +0300 Subject: [PATCH 6/6] rename sink to observer --- Tests/ActionTests.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/ActionTests.swift b/Tests/ActionTests.swift index 7df33d6f84..abd4d1ccaa 100644 --- a/Tests/ActionTests.swift +++ b/Tests/ActionTests.swift @@ -33,7 +33,7 @@ final class ActionTests: XCTestCase { } func testCompleted() { - let (producer, sink) = SignalProducer.buffer(Int.max) + let (producer, observer) = SignalProducer.buffer(Int.max) let action = Action { producer } var completed = false @@ -45,15 +45,15 @@ final class ActionTests: XCTestCase { .apply() .start() - sink.sendNext(1) + observer.sendNext(1) XCTAssertFalse(completed) - sink.sendCompleted() + observer.sendCompleted() XCTAssertTrue(completed) } func testCompletedOnFailed() { - let (producer, sink) = SignalProducer.buffer(Int.max) + let (producer, observer) = SignalProducer.buffer(Int.max) let action = Action { producer } var completed = false @@ -65,7 +65,7 @@ final class ActionTests: XCTestCase { .apply() .start() - sink.sendFailed(.Unknown) + observer.sendFailed(.Unknown) XCTAssertFalse(completed) } }