-
| Hi, I have a reactive object like this: const toolSettings = vanX.reactive({
  txX: { readable: 'Stretch X', v: 1.0, max: 4.5, center: 1.0 },
  txY: { readable: 'Stretch Y', v: 1.5, max: 4.5, center: 1.0 },
  ...
  ...
})
const rtl = van.derive(vanX.reactive(
  Object.entries(toolSettings).map(([key, v]) => [key, v.v])
))And I want to mirror it like this, so that rtl.txX matches settingsInfo.txX.v with a two way binding. Edit: const rtl = vanX.reactive(Object.fromEntries(
  Object.entries(defaultToolSettings).map(([key, v]) => [key, v.v])
))
van.derive(() => {
  const toolSettingsCollapsed = {}
  Object.entries(toolSettings).forEach(([key, value]) => {
    toolSettingsCollapsed[key] = value.v
  })
  prnt('hi', toolSettingsCollapsed)
  vanX.replace(rtl, toolSettingsCollapsed)
})This seems to work, it goes through every setting each time which I hope isn't too inefficient | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
| For your purpose, you can try "calculated fields" in VanX. | 
Beta Was this translation helpful? Give feedback.
-
| I don't think that we really need any  Try to look on const toolSettings = vanX.reactive({
  txX: { readable: 'Stretch X', v: 1.0, max: 4.5, center: 1.0 },
  txY: { readable: 'Stretch Y', v: 1.5, max: 4.5, center: 1.0 },
})
const rtl = new Proxy(toolSettings, {
	get(target, prop) {
    return target[prop].v;
  },
  set(target, prop, value) {
    return target[prop].v = value;
  }
})
van.derive(() => {
	console.log('result', rtl)
})
/**
"result", {
  txX: 1,
  txY: 1.5
}
*/
toolSettings.txY.v = 5
/**
"result", {
  txX: 1,
  txY: 5
}
*/
rtl.txX = 2
/**
"result", {
  txX: 2,
  txY: 5
}
*/ | 
Beta Was this translation helpful? Give feedback.
For your purpose, you can try "calculated fields" in VanX.