Skip to content

Commit

Permalink
Change inputs type to AnyObserver<Input> (#193)
Browse files Browse the repository at this point in the history
* improve input tests

Test that work factory is called with received inputs instead of testing that they are received on `inputs` subject

* add test cases for input receiving terminating events

* change `inputs` type to `AnyObserver<Input>`

* drop `InputSubject`

* Update changelog

(cherry picked from commit d463ba9)
  • Loading branch information
mosamer authored and freak4pc committed May 1, 2019
1 parent cb8a78a commit 5e7fb77
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 259 deletions.
17 changes: 2 additions & 15 deletions Action.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
3D730DEB1F674044008534D3 /* Button+Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D730DE81F673FD9008534D3 /* Button+Action.swift */; };
3DD965C01F5DC0E400C180FE /* Action.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FCDDA821EAC3295006EB95B /* Action.framework */; };
3DD965C61F5DC2E100C180FE /* ActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F0569F01DE288EB007E1D0D /* ActionTests.swift */; };
3DD965C81F5DC2E700C180FE /* InputSubjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C91ED6A41700BB327A /* InputSubjectTests.swift */; };
3DD965DE1F5DF8C500C180FE /* BindToTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DD965DD1F5DF86B00C180FE /* BindToTests.swift */; };
3DD965DF1F5DF8C900C180FE /* NSButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DD965DA1F5DF79800C180FE /* NSButtonTests.swift */; };
5ED520241E1EA199007621B9 /* BindToTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ED520231E1EA199007621B9 /* BindToTests.swift */; };
Expand Down Expand Up @@ -72,10 +71,6 @@
C41E08EF2237D2700039D213 /* Action+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DE00042229758700FB50AB /* Action+Extensions.swift */; };
C41E08F02237D2740039D213 /* Action+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DE00042229758700FB50AB /* Action+Extensions.swift */; };
C4DE00052229758700FB50AB /* Action+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DE00042229758700FB50AB /* Action+Extensions.swift */; };
CA2861C81ED6979400BB327A /* InputSubject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C71ED6979400BB327A /* InputSubject.swift */; };
CA2861CA1ED6A41700BB327A /* InputSubjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C91ED6A41700BB327A /* InputSubjectTests.swift */; };
CA2861CB1ED6B08300BB327A /* InputSubject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C71ED6979400BB327A /* InputSubject.swift */; };
CA2861CC1ED6B08400BB327A /* InputSubject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C71ED6979400BB327A /* InputSubject.swift */; };
FA3F973C1EDAF46F00A84787 /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F0569E21DE28587007E1D0D /* Action.swift */; };
FA3F973D1EDAF46F00A84787 /* Action+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F0569E01DE28587007E1D0D /* Action+Internal.swift */; };
FA3F973E1EDAF46F00A84787 /* InputSubject.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2861C71ED6979400BB327A /* InputSubject.swift */; };
Expand Down Expand Up @@ -166,8 +161,8 @@
C4E0264220D11A3B00C8164C /* Readme.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Readme.md; sourceTree = "<group>"; };
C4E0264320D11CDD00C8164C /* circle.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = circle.yml; sourceTree = "<group>"; };
C4E0264420D1244900C8164C /* Changelog.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Changelog.md; sourceTree = "<group>"; };
CA2861C71ED6979400BB327A /* InputSubject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputSubject.swift; sourceTree = "<group>"; };
CA2861C91ED6A41700BB327A /* InputSubjectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputSubjectTests.swift; sourceTree = "<group>"; };
FC9C4166215A99BE00541C4B /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Carthage/Build/iOS/RxCocoa.framework; sourceTree = "<group>"; };
FC9C4167215A99BE00541C4B /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -291,7 +286,6 @@
7F0569E21DE28587007E1D0D /* Action.swift */,
C4DE00042229758700FB50AB /* Action+Extensions.swift */,
7F0569E01DE28587007E1D0D /* Action+Internal.swift */,
CA2861C71ED6979400BB327A /* InputSubject.swift */,
3D730DE11F673BCB008534D3 /* CommonUI */,
7F0569E41DE28587007E1D0D /* UIKitExtensions */,
7F0569EF1DE28598007E1D0D /* Supporting Files */,
Expand Down Expand Up @@ -348,7 +342,6 @@
3DD965DC1F5DF84800C180FE /* macOS-Tests */,
3DD965DB1F5DF83700C180FE /* iOS-Tests */,
7F0569F01DE288EB007E1D0D /* ActionTests.swift */,
CA2861C91ED6A41700BB327A /* InputSubjectTests.swift */,
7F0569F41DE288EB007E1D0D /* Info.plist */,
);
path = Tests;
Expand Down Expand Up @@ -719,7 +712,6 @@
C41E08EE2237D26D0039D213 /* Action+Extensions.swift in Sources */,
3D730DEA1F674043008534D3 /* Button+Action.swift in Sources */,
1FCDDA671EAC31EF006EB95B /* UIBarButtonItem+Action.swift in Sources */,
CA2861CB1ED6B08300BB327A /* InputSubject.swift in Sources */,
3D730DE41F673C64008534D3 /* Control+Action.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -728,7 +720,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CA2861CC1ED6B08400BB327A /* InputSubject.swift in Sources */,
C41E08EF2237D2700039D213 /* Action+Extensions.swift in Sources */,
3D730DE51F673C65008534D3 /* Control+Action.swift in Sources */,
1FCDDA8A1EAC329E006EB95B /* Action.swift in Sources */,
Expand All @@ -743,7 +734,6 @@
files = (
FA3F973C1EDAF46F00A84787 /* Action.swift in Sources */,
FA3F973D1EDAF46F00A84787 /* Action+Internal.swift in Sources */,
FA3F973E1EDAF46F00A84787 /* InputSubject.swift in Sources */,
C41E08F02237D2740039D213 /* Action+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -755,7 +745,6 @@
3DD965DE1F5DF8C500C180FE /* BindToTests.swift in Sources */,
3DD965C61F5DC2E100C180FE /* ActionTests.swift in Sources */,
3DD965DF1F5DF8C900C180FE /* NSButtonTests.swift in Sources */,
3DD965C81F5DC2E700C180FE /* InputSubjectTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -769,7 +758,6 @@
7F0569F51DE288EB007E1D0D /* ActionTests.swift in Sources */,
7B4BFE6320C290BF00D72FB0 /* RefreshControlTests.swift in Sources */,
7F0569F81DE288EB007E1D0D /* ButtonTests.swift in Sources */,
CA2861CA1ED6A41700BB327A /* InputSubjectTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -792,7 +780,6 @@
7F0569ED1DE28587007E1D0D /* UIBarButtonItem+Action.swift in Sources */,
C4DE00052229758700FB50AB /* Action+Extensions.swift in Sources */,
3D730DE91F673FD9008534D3 /* Button+Action.swift in Sources */,
CA2861C81ED6979400BB327A /* InputSubject.swift in Sources */,
3D730DE31F673BE4008534D3 /* Control+Action.swift in Sources */,
7F0569EA1DE28587007E1D0D /* Action.swift in Sources */,
);
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Nimble" "v8.0.1"
github "Quick/Quick" "v2.0.0"
github "ReactiveX/RxSwift" "4.4.2"
github "Quick/Quick" "v2.1.0"
github "ReactiveX/RxSwift" "4.5.0"
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
Current master
--------------
- Add `completions` property to `CompletableAction`
- Change `inputs` type to `AnyObserver<Input>`

3.11.0
-------
Expand Down
15 changes: 9 additions & 6 deletions Sources/Action/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ public final class Action<Input, Element> {
public let _enabledIf: Observable<Bool>
public let workFactory: WorkFactory

/// Inputs that triggers execution of action.
/// This subject also includes inputs as aguments of execute().
/// All inputs are always appear in this subject even if the action is not enabled.
/// Thus, inputs count equals elements count + errors count.
public let inputs = InputSubject<Input>()
/// Bindable sink for inputs that triggers execution of action.
public let inputs: AnyObserver<Input>

/// Errors aggrevated from invocations of execute().
/// Delivered on whatever scheduler they were sent from.
Expand Down Expand Up @@ -76,7 +73,13 @@ public final class Action<Input, Element> {
let errorsSubject = PublishSubject<ActionError>()
errors = errorsSubject.asObservable()

executionObservables = inputs
let inputsSubject = PublishSubject<Input>()
inputs = AnyObserver { event in
guard case .next(let value) = event else { return }
inputsSubject.onNext(value)
}

executionObservables = inputsSubject
.withLatestFrom(enabled) { input, enabled in (input, enabled) }
.flatMap { input, enabled -> Observable<Observable<Element>> in
if enabled {
Expand Down
93 changes: 0 additions & 93 deletions Sources/Action/InputSubject.swift

This file was deleted.

Loading

0 comments on commit 5e7fb77

Please sign in to comment.