Skip to content

Combine Worker #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Development.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Pod::Spec.new do |s|
s.dependency 'WorkflowUI'
s.dependency 'WorkflowReactiveSwift'
s.dependency 'WorkflowRxSwift'
# s.dependency 'WorkflowCombine' # TODO: Disabled because app specs cannot increase the deployment target of the root
s.source_files = 'Samples/Dummy.swift'

s.subspec 'Dummy' do |ss|
Expand Down Expand Up @@ -141,4 +142,14 @@ Pod::Spec.new do |s|
test_spec.dependency 'WorkflowTesting'
test_spec.dependency 'WorkflowRxSwiftTesting'
end

# TODO: Disabled because app specs cannot increase the deployment target of the root
# To use, increase the deployment target of this spec to 13.0 or higher
# s.test_spec 'WorkflowCombineTests' do |test_spec|
# test_spec.requires_app_host = true
# test_spec.source_files = 'WorkflowCombine/Tests/**/*.swift'
# test_spec.framework = 'XCTest'
# test_spec.dependency 'WorkflowTesting'
# test_spec.dependency 'WorkflowCombineTesting'
# end
end
9 changes: 9 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ let package = Package(
name: "WorkflowReactiveSwift",
targets: ["WorkflowReactiveSwift"]
),
.library(
name: "WorkflowCombine",
targets: ["WorkflowCombine"]
),
],
dependencies: [
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "6.3.0"),
Expand Down Expand Up @@ -62,6 +66,11 @@ let package = Package(
dependencies: ["ReactiveSwift", "Workflow"],
path: "WorkflowReactiveSwift/Sources"
),
.target(
name: "WorkflowCombine",
dependencies: ["Workflow"],
path: "WorkflowCombine/Sources"
),
],
swiftLanguageVersions: [.v5]
)
18 changes: 18 additions & 0 deletions Samples/WorkflowCombineSampleApp/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
project 'WorkflowCombineSampleApp.xcodeproj'
platform :ios, '13.0'

target 'WorkflowCombineSampleApp' do
pod 'Workflow', path: '../../Workflow.podspec', :testspecs => ['Tests']
pod 'WorkflowUI', path: '../../WorkflowUI.podspec', :testspecs => ['Tests']
pod 'WorkflowCombine', path: '../../WorkflowCombine.podspec'
pod 'WorkflowReactiveSwift', path: '../../WorkflowReactiveSwift.podspec', :testspecs => ['Tests']

target 'WorkflowCombineSampleAppUnitTests' do
inherit! :search_paths

pod 'Workflow', path: '../../Workflow.podspec', :testspecs => ['Tests']
pod 'WorkflowCombine', path: '../../WorkflowCombine.podspec'
pod 'WorkflowReactiveSwift', path: '../../WorkflowReactiveSwift.podspec', :testspecs => ['Tests']
pod 'WorkflowUI', path: '../../WorkflowUI.podspec', :testspecs => ['Tests']
end
end
58 changes: 58 additions & 0 deletions Samples/WorkflowCombineSampleApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
PODS:
- ReactiveSwift (6.3.0)
- Workflow (1.0.0-rc.1):
- ReactiveSwift (~> 6.3.0)
- Workflow/Tests (1.0.0-rc.1):
- ReactiveSwift (~> 6.3.0)
- WorkflowCombine (1.0.0-rc.1):
- Workflow (= 1.0.0-rc.1)
- WorkflowReactiveSwift (1.0.0-rc.1):
- ReactiveSwift (~> 6.3.0)
- Workflow (= 1.0.0-rc.1)
- WorkflowReactiveSwift/Tests (1.0.0-rc.1):
- ReactiveSwift (~> 6.3.0)
- Workflow (= 1.0.0-rc.1)
- WorkflowTesting (= 1.0.0-rc.1)
- WorkflowTesting (1.0.0-rc.1):
- Workflow (= 1.0.0-rc.1)
- WorkflowUI (1.0.0-rc.1):
- Workflow (= 1.0.0-rc.1)
- WorkflowUI/Tests (1.0.0-rc.1):
- Workflow (= 1.0.0-rc.1)
- WorkflowReactiveSwift (= 1.0.0-rc.1)

DEPENDENCIES:
- Workflow (from `../../Workflow.podspec`)
- Workflow/Tests (from `../../Workflow.podspec`)
- WorkflowCombine (from `../../WorkflowCombine.podspec`)
- WorkflowReactiveSwift (from `../../WorkflowReactiveSwift.podspec`)
- WorkflowReactiveSwift/Tests (from `../../WorkflowReactiveSwift.podspec`)
- WorkflowUI (from `../../WorkflowUI.podspec`)
- WorkflowUI/Tests (from `../../WorkflowUI.podspec`)

SPEC REPOS:
trunk:
- ReactiveSwift
- WorkflowTesting

EXTERNAL SOURCES:
Workflow:
:path: "../../Workflow.podspec"
WorkflowCombine:
:path: "../../WorkflowCombine.podspec"
WorkflowReactiveSwift:
:path: "../../WorkflowReactiveSwift.podspec"
WorkflowUI:
:path: "../../WorkflowUI.podspec"

SPEC CHECKSUMS:
ReactiveSwift: 7937f26ec18d555e2a99352bd0a8b2817d1f042d
Workflow: e3391755e611eb0e0efc244ef5fa9b12c6e2f8ab
WorkflowCombine: 8806745d6023261bfbc34e0d1da753774e9fe0c5
WorkflowReactiveSwift: a1854c330a7ea4342e999156e0abe7f216e16d63
WorkflowTesting: ff584e427bda8491285deb97db14182925d1e4f4
WorkflowUI: 0e3b93590dc2e58a93f300a47e5c8e81b501ef36

PODFILE CHECKSUM: 0a8cc7b6b118ae7091c5f1104b8d8cbffe43c04f

COCOAPODS: 1.9.1
48 changes: 48 additions & 0 deletions Samples/WorkflowCombineSampleApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# WorkflowCombineSampleApp

This sample project utilizes the WorkflowCombine library to demonstrate its usage in a `Workflow`. It is a simple app with a label that updates the current date & time every second.

# Usage

Thanks to the `AnyWorkflowConvertible` protocol, both the `WorkflowReactiveSwift` and `WorkflowCombine` Workers have identical api interface. To to migrate your `WorkflowReactiveSwift` `Worker`s to use the `WorkflowCombine` `Worker`s, you will need to do the following:

1. Change `import` statements to use `WorkflowCombine` and `Combine`
2. Replace `SignalProducer` into `AnyPublisher` for the return type of `run`
3. Change the `run` implementation to the `Combine` equivalence. Most likely this will be the step that that requires the most attention, however if the tests were written for the `Workflow` it can be used to validate the new implementation without the need to change the tests.

Below is an example of a simple `Worker` in both `WorkflowReactiveSwift` and `WorkflowCombine` that emits a signal every second with the current date.

### `WorkflowReactiveSwift`

```swift
struct TimerWorker: Worker {
typealias Output = Date

func run() -> SignalProducer<Output, Never> {
SignalProducer
.timer(interval: DispatchTimeInterval.seconds(1), on: QueueScheduler.main)
}

func isEquivalent(to otherWorker: TimerWorker2) -> Bool { true }
}
```

### `WorkflowCombine`

```swift
struct TimerWorker: Worker {
typealias Output = Date

func run() -> AnyPublisher<Output, Never> {
Timer.publish(every: 1, on: .main, in: .common)
.autoconnect()
.eraseToAnyPublisher()
}

func isEquivalent(to otherWorker: Self) -> Bool { true }
}
```

### Notes

This library does **not** remove the usage of the `ReactiveSwift` library from the `Workflow` library. Currently the `Workflow` implementation is tightly coupled with `ReactiveSwift`, and this library is only limited to the `Worker`. Therefore, when utilizing both the existing `Workflow` and the new `Combine` backed `Worker` , you will need to utilize both the `ReactiveSwift` and `Combine` libraries.
Loading