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

edit mode : state initialisation not sync with input text #24

Closed
PierreBrisorgueil opened this issue May 7, 2019 · 2 comments · Fixed by #25
Closed

edit mode : state initialisation not sync with input text #24

PierreBrisorgueil opened this issue May 7, 2019 · 2 comments · Fixed by #25

Comments

@PierreBrisorgueil
Copy link
Contributor

PierreBrisorgueil commented May 7, 2019

Hello,

just a little trouble I met, from the code I saw :

TaskEditViewReactor.swift

  init(provider: ServiceProviderType, mode: TaskEditViewMode) {
    self.provider = provider
    self.mode = mode

    switch mode {
    case .new:
      self.initialState = State(title: "New", taskTitle: "", canSubmit: false)
    case .edit(let task):
      self.initialState = State(title: "Edit", taskTitle: task.title, canSubmit: true)
      print("test 0 \(self.initialState)")
    }
  }

TaskEditViewController

    reactor.state.asObservable().map { $0.taskTitle }
      .distinctUntilChanged()
      .bind(to: self.titleInput.rx.text)
      .disposed(by: self.disposeBag)

I think the goal was to open the new view in edit mode with the input initiated with the text of the task to modify ?

if I understood everything, it's a bug, the input is empty in edit mode, I had the same problem on my side, I fixed it quickly by the initialization of the controller but I am sure that there is better to do.

@audrl1010
Copy link

audrl1010 commented May 30, 2019

Since rx.text is ControlProperty, it sends initial value (empy string) when initial subscribe, therefore it sends Reactor.Action.updateTitles to reactor.action . So skip the initial value(empty string) when subscribing.

self.titleInput.rx.text.filterNil()
.skip(1)
.map(Reactor.Action.updateTaskTitle)
.bind(to: reactor.action)
.disposed(by: self.disposeBag)

@PierreBrisorgueil
Copy link
Contributor Author

Perfect, thank you for this clarification and your time, i did not think about it. (PR on my Stack / Boilerplate, i will PR here asap to close the issue)

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

Successfully merging a pull request may close this issue.

2 participants