My app works with the following kind of data: There are companies which each have a list of datapoints. Each datapoint has a single type and each company can only have one datapoint of each type.
+Company_1
|
|--Datapoint_1 : type_1
|--Datapoint_2 : type_2
|--Datapoint_3 : type_3
|
|
+Company_2
|
|--Datapoint_4 : type_3
|--Datapoint_5 : type_2
|
|+Company_3
|
|--Datapoint_6 : type_2
...
...
In total there are about 1000 datapoints and 20 companies. The app calculates analytics based on these datapoints and the goal is to allow users to manipulate these datapoints in order to see what the results would look like in a given scenario. At any given moment, there is a "selected_company" and "selected_type" and based on these two selections, the correct datapoint should be chosen for manipulation.
I realised that if the "companies" variable, and "datapoints" property were arrays, a search would have to be done on all the items in order to find the correct ones. I therefore chose to make them objects :
companies = {
'1' : {
name : 'Company_1',
datapoints : {
'type_1' : { ... },
'type_2' : { ... },
'type_3' : { ... }
}
},
'2' : {...},
'3' : {...},
.
.
.
}
Problem:
I have a 'datapoint' component, that I am passing datapoints as props :
<datum-comp :datum="companies[selected_company].datapoints[selected_type]"></datum-comp>
Within this component, I have an input that is used to manipulate the score property of the datapoint:
<input v-model.number="datum.score" class="form-control">
However, this input is exhibiting very strange behaviour. As I type into the input, the model is not immediately updated. Instead, Vue seems to be waiting for me to change focus from the input (onBlur) before updating the model.
Even more weird, is that when I make the datapoints property an array
companies = {
'1' : {
name : 'Company_1',
datapoints : [
{ ... },
{ ... },
{ ... }
]
},
and use a method to retrieve the datapoint (as opposed to directly passing it in), Vue functions the correct way!
<datum-comp :datum="getDatum(selected_company, selected_type)"></datum-comp>
(in js file:)
var app = new Vue({
el : '#app',
data:{...},
methods:{
getDatum: function(selected_company, selected_type){
var datum = this.companies[selected_company].datapoints.find(function(elem){
return elem.type == selected_type
})
return datun
}
}
})
I need help understanding why Vue behaves like this under these circumstances as it has some serious implications for app performance. Thanks in advance.
@input=""
and then call a function that does the update instead. – connexo