-
Notifications
You must be signed in to change notification settings - Fork 54
Description
I am having trouble to follow the framework when it comes to the Feedback
context and although you can read the code, not sure how (some) feedbacks are connected to the event, it looks like there are various flavors of Feedback
, some are invoked every time state change and some are not making it difficult to understand when to use what.
Example:
// Having the below ViewModel
final class ViewModel: CombineFeedbackUI.Store<HostBroadcast.State, HostBroadcast.Event> {
init(initial: State = State()){
super.init(
initial: initial,
feedbacks: [
ViewModel.whenBroadcastFinished(),
ViewModel.whenSomethingElseHappened()
],
reducer: HostBroadcast.reducer
)
}
static func whenSomethingElseHappened() -> Feedback<State, Event> {
return Feedback.custom { state, consumer in
print("whenSomethingElseHappened")
return Empty().eraseToAnyPublisher().start()
}
}
static func whenBroadcastFinished() -> Feedback<State, Event> {
return Feedback(effects: { (state) -> AnyPublisher<Event, Never> in
print("\(state.status)")
guard state.status.isBroadcastFinished else {
print("#Broadcast not finished...")
return Empty().eraseToAnyPublisher()
}
print("#Broadcast finished...")
return Empty().eraseToAnyPublisher()
})
}
}
whenSomethingElseHappened
feedback will execute when the whole view is redrawn by the system; in my case every time a tab item selected change, but not when a button action in the view or onAppear
emits an event Button(action: context.action(for: .didFinishBroadcast))
, .onAppear { self.context.send(event: .shouldConnect) }
I'd appreciate it if I can further read somewhere how the Feedback lifecycle or connection to the events raised is working. I can also help with documentation.