Skip to content

Commit

Permalink
equatable ScreenActionSink
Browse files Browse the repository at this point in the history
  • Loading branch information
square-tomb committed Jun 22, 2023
1 parent c9e359c commit 713087b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Samples/TicTacToe/Sources/Authentication/LoginScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import SwiftUI
import Workflow
import WorkflowSwiftUI

struct LoginScreen: SwiftUIScreen {
var actionSink: Sink<LoginWorkflow.Action>
struct LoginScreen: SwiftUIScreen, Equatable {
var actionSink: ScreenActionSink<LoginWorkflow.Action>
var title: String
var email: String
var password: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension LoginWorkflow {

func render(state: LoginWorkflow.State, context: RenderContext<LoginWorkflow>) -> Rendering {
LoginScreen(
actionSink: context.makeSink(of: Action.self),
actionSink: .init(context.makeSink(of: Action.self)),
title: "Welcome! Please log in to play TicTacToe!",
email: state.email,
password: state.password
Expand Down
17 changes: 17 additions & 0 deletions WorkflowSwiftUI/Sources/ObservableValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ public final class ObservableValue<Value>: ObservableObject {
}
}

public struct ScreenActionSink<Value>: Equatable {
private let sink: Sink<Value>

// TODO: Only allow this to be initialized by `WorkflowNode.SubtreeManager.Context`?
public init(_ sink: Sink<Value>) {
self.sink = sink
}

public func send(_ value: Value) {
sink.send(value)
}

public static func == (lhs: ScreenActionSink<Value>, rhs: ScreenActionSink<Value>) -> Bool {
true
}
}

#if canImport(UIKit)

public extension ObservableValue where Value: SwiftUIScreen {
Expand Down
2 changes: 1 addition & 1 deletion WorkflowSwiftUI/Sources/SwiftUIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public protocol SwiftUIScreen: Screen {
@ViewBuilder
static func makeView(model: ObservableValue<Self>) -> Content

var actionSink: Sink<Action> { get }
var actionSink: ScreenActionSink<Action> { get }

static var isDuplicate: ((Self, Self) -> Bool)? { get }
}
Expand Down

0 comments on commit 713087b

Please sign in to comment.