Philipp Smorygo [JB]
04/10/2022, 3:23 AMbind(AppManager.store.sub { it.commercialProposalState to it.customerState }) { states ->
  commercialProposalEdit(states.first, states.second)
}
This view is shown only when state.coreState.view == CP_EDIT
Also this view uses some fields from
Then I dispatch an event that changes state.coreState.view  and sets state.customerState  fields to null.
After that I got an exception that  some field from state.customerState  is null. But view state.coreState.view  is already changed so my component should not update anymore. It looks like it’s updated first, and only then it is replaced by another view. It seems that this update should not happen, because the component should be disposed before it’s update could be triggered
Also this breaks the app and my commercialProposalEdit component is never disposed and on every state change it throws an exception. So only reloading the page helps.Robert Jaros
04/10/2022, 5:50 AMRobert Jaros
04/10/2022, 6:05 AMObservableValue and with redux modules.Robert Jaros
04/10/2022, 6:06 AMRobert Jaros
04/10/2022, 6:13 AMRobert Jaros
04/10/2022, 6:19 AMbindSync instead of bind on your view top level binding. This will make your components disposed immediately when the view is changed.Robert Jaros
04/10/2022, 6:24 AMRobert Jaros
04/10/2022, 6:26 AMStateFlow as the store. It's probably because the flow is also asynchronous by design.Robert Jaros
04/10/2022, 6:44 AMsub is registering a new subscription. In your code there is nothing that can cancel this subscription and your code is calling sub many times (on every state change). You are leaking memory and degrading performance here.Robert Jaros
04/10/2022, 6:46 AMsub function allows you to bind this subscription with a component (and the subscription will be canceled when the component is disposed). You can just pass a component as the first parameter of sub.
bind(AppManager.store.sub(this) { it.commercialProposalState to it.customerState }) { states ->
  commercialProposalEdit(states.first, states.second)
}Robert Jaros
04/10/2022, 6:49 AMbind with two parameters:
bind(AppManager.store, { it.commercialProposalState to it.customerState }) { states ->
  commercialProposalEdit(states.first, states.second)
}
which will automatically connect store, the given function and the component for disposal and subscription cancelationPhilipp Smorygo [JB]
04/10/2022, 11:28 AMbind is called on a Div that’s created within another bind, which is called on RootPhilipp Smorygo [JB]
04/10/2022, 11:30 AMroot("kvapp") {
  bind(AppManager.store.sub { it.coreState }) { coreState ->
    div(className = "page") {
      div(className = "page-content container-fluid") {
        when (coreState.view) {
          View.SUPPLIERS -> {
            bind(AppManager.store.sub { it.supplierState }) { state ->
              suppliers(state)
            }
          }
          ...
        } ...
}