-
|
Hi I'm wondering if it would be possible to call van.derive on dynamically specified objects. Say i have following data structure and all children need to be "reactive" through a van.derive call this.data = vanX.reactive({
power: {
value: null
},
volume: {
value: null
},
...
});`would it be possible to create a function along the lines of this, where the van state object is passed as a parameter? setReactive (variable, callback) {
//some generel preceeding logic
van.derive(() => {
if (!this.data[variable].serverFlag) {
//not a get request update, therefore post to server
callback(this.data[variable].value);
}
//reset flag
this.data[variable].serverFlag = false;
});
}the function call would be along the lines of I have played around but not gotten any results. I suspect due to the nature of how construct the inside of the van.derive function or something glaring I have overlooked Any help is appreciated, and it its merely a question out of interest :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
I'm not able to figure out what you tried to do from the pieces of code you just pasted. Specifically:
Could you provide the full context of the code, what's the actual behavior as well as what's your expected behavior? |
Beta Was this translation helpful? Give feedback.
-
|
yes of course. The samples of code weren't meant to compile. I have many more members of Hope this clears it up a bit |
Beta Was this translation helpful? Give feedback.
Your guess is right. If
serverFlagisfalse, thethenbranch of theifstatement won't be executed thusthis.data[variable].valuewon't be accessed and registered as a dependency of the derivation. Whenever you turnserverFlagtotrue,this.data[variable].valuewill be accessed and registered as the dependency of the derivation.