Hi! I have a question regarding `bind` function, p...
# kvision
i
Hi! I have a question regarding
bind
function, probably I just don't understand how should I work with it. Details in thread
I have following code:
Copy code
val restaurantsState = MutableStateFlow(listOf<RestaurantDto>())                                               
val selectedRestaurantBind = MutableStateFlow<String?>(null)                                                   
val selectedRestaurantSubscribe = MutableStateFlow<String?>(null)                                              
root("kvapp") {                                                                                                 
    select(label = "Restaurant bind").bind(restaurantsState.observableState) { restaurants ->                  
        options = restaurants.map { it.id.value to it.name }                                                   
    }.bindTo(selectedRestaurantBind)                                                                           
    select(label = "Restaurant subscribe") {                                                                    
        restaurantsState.observableState.subscribe { restaurants ->                                            
            options = restaurants.map { it.id.value to it.name }                                               
        }                                                                                                      
    }.bindTo(selectedRestaurantSubscribe)                                                                      
    listTag(ListType.UL).bindEach(restaurantsState) { restaurant ->                                            
        +restaurant.name                                                                                       
    }                                                                                                          
    button("Add restaurant") {                                                                                  
        var count = 0                                                                                          
        onClick {                                                                                               
            restaurantsState.update { it + RestaurantDto(RestaurantId(count.toString()), "Restaurant $count") }
            count++                                                                                            
        }                                                                                                      
    }                                                                                                          
}
Whenever I click the "Add restaurant" button, new restaurant does not appear in "Restaurant bind" select and appears in "Restaurant subscribe". In fact, "Restaurant bind" contains previous state, so if I add 3 restaurants it shows "Restaurant 0" and "Restaurant 1". What am I doing wrong and what should I do for such use case?
Copy code
listTag(ListType.UL)
    .bind(restaurantsState) { restaurants ->
        elements = restaurants.map { it.name }
    }
List tag renders all items properly with the similar approach
r
Hi
It doesn't seem to be the problem with binding. Your code works perfectly fine when I replace
select
with
simpleSelect
component.
It seems to be a problem with refreshing
Select
component.
I'll check this out. Please fill the issue in the meantime, if you don't mind.
i
Yes, with
simpleSelect
it works fine. I created an issue https://github.com/rjaros/kvision/issues/312
🙏 1
r
Found and fixed. Going to release 5.2.1 later today.