Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation - I can help #32

Open
xplatsolutions opened this issue Jun 26, 2020 · 0 comments
Open

Documentation - I can help #32

xplatsolutions opened this issue Jun 26, 2020 · 0 comments

Comments

@xplatsolutions
Copy link

xplatsolutions commented Jun 26, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant