title: MVVM implementation with RxSwift and Realm - Two way binding
body: <p>My implementation of the MVVM pattern with RxSwift, Realm and RxRealm looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/ud6iz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ud6iz.png" alt="MVVM pattern with realm and RxSwift"></a></p>
  
  <p>E.g. I have a textfield that shows some editable content. I want this to be realtime saved/synched to the DB like this: </p>
  
  <pre><code>//View
  textField.rx.text.subscribe(textViewModel.saveText.inputs)
  viewModel.stringValue.drive(textField.rx.text)
  
  //ViewModel:
  lazy var saveText = Action&lt;String,Void&gt;{ newStringValue in 
     realm.write{
       textObject.stringValue = newStringValue
     }
    //don't block the main thread
    return Observable.just()
  }  
  
  lazy var stringValue = Observable(from:textObject).map{$0.stringValue}.asDriver(onErrorJustReturn : "no string")
  </code></pre>
  
  <p>When typing slowly in the TextField, everything works accordingly. When typing very quickly thought, letters get "swallowed" like this: </p>
  
  <ol>
  <li>Type "A"</li>
  <li>write "A" to DB</li>
  <li>Type "B"</li>
  <li>Receive "A" from DB 
  -> Textfield value becomes A instead of AB. </li>
  </ol>
  
  <p>When working with realtime synchronization this is the desired behaviour. For single text typing this seems not a good solution. How would such a 2-way binding be properly implemented and the undesired effect be avoided, especially in a scenario where the viewModel is processing the text value before  write or after read from the source?</p>