-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIResponseCellViewModel.swift
More file actions
44 lines (36 loc) · 1009 Bytes
/
AIResponseCellViewModel.swift
File metadata and controls
44 lines (36 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Combine
extension AIResponseCellViewModel {
struct Input {
let onError = PassthroughSubject<Error, Never>()
}
struct Output {
let markdown: String
let onError = PassthroughSubject<Error, Never>()
}
struct Config {
let markdown: String
}
}
final class AIResponseCellViewModel: BaseViewModel, Identifiable {
let input = Input()
let output: Output
lazy var id = ObjectIdentifier(self)
init(config: Config) {
self.output = Output(markdown: config.markdown)
super.init()
bind()
}
private func bind() {
input.onError
.subscribe(output.onError)
.store(in: &cancellables)
}
}
extension AIResponseCellViewModel: Hashable {
static func == (lhs: AIResponseCellViewModel, rhs: AIResponseCellViewModel) -> Bool {
return lhs.hashValue == rhs.hashValue
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}