-
Notifications
You must be signed in to change notification settings - Fork 47
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
Combine Worker #104
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
de75910
Create WorkflowCombine library
soorinpark decc7c0
Create Worker backed with Combine Publisher
soorinpark b06a710
Add Testing modules and podspec
soorinpark 41a3c57
Completed same test suite as the WorkflowReactiveSwift library
soorinpark 262c8da
Add missing Publisher tests
soorinpark c647ee7
Create a sample app for Combine backed worker
soorinpark 9f0b8fc
Fixed testPublisherWorkflow's TestWorkflow implmentation
soorinpark c00fecc
Remove WorkflowCombineTestingTests target from podspec
soorinpark f7a096b
Add tests to WorkflowCombineSampleApp
soorinpark ecf518d
Add README for WorkflowCombineSampleApp
soorinpark 525a936
Create WorkflowCombineSampleApp through podspec instead
soorinpark 55db045
handle cancelling cancellable on lifetime ending
soorinpark d54c04d
Remove references of WorkflowReactiveSwift from WorkflowCombineSampleApp
soorinpark 2057460
Removed unwanted files
soorinpark 2b727df
Fix Workflows to take a generic publisher type
soorinpark 07fd80a
Remove the need to type-erase publisher to render the workflow view
soorinpark c4d4d10
Separate WorkflowCombineTesting module
soorinpark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp/AppDelegate.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// AppDelegate.swift | ||
// WorkflowCombineSampleApp | ||
// | ||
// Created by Soo Rin Park on 10/28/21. | ||
// | ||
|
||
import UIKit | ||
import WorkflowUI | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
var window: UIWindow? | ||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
window = UIWindow(frame: UIScreen.main.bounds) | ||
window?.rootViewController = ContainerViewController(workflow: DemoWorkflow()) | ||
window?.makeKeyAndVisible() | ||
|
||
return true | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp/DemoViewController.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// DemoViewController.swift | ||
// WorkflowCombineSampleApp | ||
// | ||
// Created by Soo Rin Park on 10/28/21. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import WorkflowUI | ||
|
||
class DemoViewController: ScreenViewController<DemoScreen> { | ||
private let label = UILabel() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
label.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(label) | ||
label.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | ||
label.topAnchor.constraint(equalTo: view.topAnchor).isActive = true | ||
label.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | ||
label.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true | ||
} | ||
|
||
override func screenDidChange(from previousScreen: DemoScreen, previousEnvironment: ViewEnvironment) { | ||
super.screenDidChange(from: previousScreen, previousEnvironment: previousEnvironment) | ||
|
||
label.text = screen.date | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp/DemoWorker.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// DemoWorker.swift | ||
// WorkflowCombineSampleApp | ||
// | ||
// Created by Soo Rin Park on 10/28/21. | ||
// | ||
|
||
import Combine | ||
import Workflow | ||
import WorkflowCombine | ||
import WorkflowUI | ||
|
||
// MARK: Workers | ||
|
||
extension DemoWorkflow { | ||
struct DemoWorker: WorkflowCombine.Worker { | ||
typealias Output = Action | ||
|
||
// This publisher publishes the current date on a timer that fires every second | ||
func run() -> AnyPublisher<Action, Never> { | ||
Timer.publish(every: 1, on: .main, in: .common) | ||
.autoconnect() | ||
.map { Action(publishedDate: $0) } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
func isEquivalent(to otherWorker: DemoWorkflow.DemoWorker) -> Bool { true } | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp/DemoWorkflow.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// DemoWorkflow.swift | ||
// WorkflowCombineSampleApp | ||
// | ||
// Created by Soo Rin Park on 10/28/21. | ||
// | ||
|
||
import Workflow | ||
import WorkflowUI | ||
|
||
// MARK: Input and Output | ||
|
||
let dateFormatter = DateFormatter() | ||
|
||
struct DemoWorkflow: Workflow { | ||
typealias Output = Never | ||
} | ||
|
||
// MARK: State and Initialization | ||
|
||
extension DemoWorkflow { | ||
struct State: Equatable { | ||
var date: Date | ||
} | ||
|
||
func makeInitialState() -> DemoWorkflow.State { State(date: Date()) } | ||
|
||
func workflowDidChange(from previousWorkflow: DemoWorkflow, state: inout State) {} | ||
} | ||
|
||
// MARK: Actions | ||
|
||
extension DemoWorkflow { | ||
struct Action: WorkflowAction { | ||
typealias WorkflowType = DemoWorkflow | ||
|
||
let publishedDate: Date | ||
|
||
func apply(toState state: inout DemoWorkflow.State) -> DemoWorkflow.Output? { | ||
state.date = publishedDate | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
// MARK: Rendering | ||
|
||
extension DemoWorkflow { | ||
// TODO: Change this to your actual rendering type | ||
typealias Rendering = DemoScreen | ||
|
||
func render(state: DemoWorkflow.State, context: RenderContext<DemoWorkflow>) -> Rendering { | ||
DemoWorker() | ||
.rendered(in: context) | ||
|
||
dateFormatter.dateStyle = .long | ||
dateFormatter.timeStyle = .long | ||
let formattedDate = dateFormatter.string(from: state.date) | ||
let rendering = Rendering(date: formattedDate) | ||
|
||
return rendering | ||
} | ||
} | ||
|
||
struct DemoScreen: Screen { | ||
let date: String | ||
|
||
func viewControllerDescription(environment: ViewEnvironment) -> ViewControllerDescription { | ||
DemoViewController.description(for: self, environment: environment) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleAppUnitTests/DemoWorkflowTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// DemoWorkflowTests.swift | ||
// WorkflowCombineSampleAppUnitTests | ||
// | ||
// Created by Soo Rin Park on 11/1/21. | ||
// | ||
|
||
import Combine | ||
import Workflow | ||
import WorkflowTesting | ||
import XCTest | ||
@testable import Development_WorkflowCombineSampleApp | ||
|
||
class DemoWorkflowTests: XCTestCase { | ||
func test_workflowIsRenderedEverySecondForFiveSeconds() { | ||
let expectedDate = Date(timeIntervalSince1970: 0) | ||
|
||
DemoWorkflow | ||
.Action | ||
.tester(withState: .init(date: Date())) // the initial date itself does not matter | ||
.send(action: .init(publishedDate: expectedDate)) | ||
.assert(state: .init(date: expectedDate)) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require_relative('version') | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'WorkflowCombine' | ||
s.version = WORKFLOW_VERSION | ||
s.summary = 'Infrastructure for Combined-powered Workers' | ||
s.homepage = 'https://www.github.com/square/workflow-swift' | ||
s.license = 'Apache License, Version 2.0' | ||
s.author = 'Square' | ||
s.source = { :git => 'https://github.com/square/workflow-swift.git', :tag => "v#{s.version}" } | ||
|
||
# 1.7 is needed for `swift_versions` support | ||
s.cocoapods_version = '>= 1.7.0' | ||
|
||
s.swift_versions = ['5.1'] | ||
s.ios.deployment_target = '13.0' | ||
s.osx.deployment_target = '10.15' | ||
|
||
s.source_files = 'WorkflowCombine/Sources/*.swift' | ||
|
||
s.dependency 'Workflow', "#{s.version}" | ||
|
||
end | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.