-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path___FILEBASENAME___View.swift
executable file
·74 lines (54 loc) · 1.94 KB
/
___FILEBASENAME___View.swift
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//___FILEHEADER___
import SwiftUI
struct ___VARIABLE_sceneName___View {
@StateObject var container: MVIContainer<___VARIABLE_sceneName___IntentProtocol, ___VARIABLE_sceneName___ModelStatePotocol>
private var intent: ___VARIABLE_sceneName___IntentProtocol { container.intent }
private var state: ___VARIABLE_sceneName___ModelStatePotocol { container.model }
init(data: ___VARIABLE_sceneName___ExternalData) {
let model = ___VARIABLE_sceneName___Model()
let intent = ___VARIABLE_sceneName___Intent(model: model, externalData: data)
let container = MVIContainer(
intent: intent as ___VARIABLE_sceneName___IntentProtocol,
model: model as ___VARIABLE_sceneName___ModelStatePotocol,
modelChangePublisher: model.objectWillChange
)
self._container = StateObject(wrappedValue: container)
}
}
// MARK: - View
extension ___VARIABLE_sceneName___View: View {
var body: some View {
Text(state.text)
.modifier(___VARIABLE_sceneName___Router(
routerEvents: state.routerEvents,
delegate: intent as? ___VARIABLE_sceneName___RouterDelegate
))
.onAppear(perform: intent.viewOnAppear)
.onDisappear(perform: intent.viewOnDisappear)
}
}
#if DEBUG
// MARK: - Previews
#Preview {
___VARIABLE_sceneName___View(data: ___VARIABLE_sceneName___ExternalData())
}
#endif
// MARK: - MVIContainer
import SwiftUI
import Combine
final private class MVIContainer<Intent, Model>: ObservableObject {
// MARK: Public
let intent: Intent
let model: Model
// MARK: private
private var cancellable: Set<AnyCancellable> = []
// MARK: Life cycle
init(intent: Intent, model: Model, modelChangePublisher: ObjectWillChangePublisher) {
self.intent = intent
self.model = model
modelChangePublisher
.receive(on: RunLoop.main)
.sink(receiveValue: objectWillChange.send)
.store(in: &cancellable)
}
}