Skip to content

Commit f631dfb

Browse files
committed
+ ViewCoordinator
1 parent 83089b7 commit f631dfb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// ViewCoordinator.swift
3+
// ComposableViewPattern
4+
//
5+
// Created by Jonathan Holland on 3/9/24.
6+
//
7+
8+
import SwiftUI
9+
10+
public protocol ViewCoordinator {
11+
associatedtype ContentView: View
12+
var view: ContentView { get }
13+
var state: ViewCoordinatorState { get }
14+
15+
func load() async
16+
func reload() async
17+
}
18+
19+
extension ViewCoordinator {
20+
public func load() async {}
21+
public func reload() async {}
22+
}
23+
24+
public enum ViewCoordinatorState: Equatable {
25+
public static func == (lhs: ViewCoordinatorState, rhs: ViewCoordinatorState) -> Bool {
26+
if case let .error(lhsError) = lhs, case let .error(rhsError) = rhs {
27+
return lhsError?.localizedDescription == rhsError?.localizedDescription
28+
} else if case .idle = lhs, case .idle = rhs {
29+
return true
30+
} else if case .loaded = lhs, case .loaded = rhs {
31+
return true
32+
} else if case .needsReload = lhs, case .needsReload = rhs {
33+
return true
34+
}
35+
return false
36+
}
37+
38+
case idle
39+
case loaded
40+
case needsReload
41+
case error(error: Error? = nil)
42+
}

0 commit comments

Comments
 (0)