Frontmatter
| id | 5591 |
| title | model.Component: enhance 2way-bindings |
| state | Closed |
| labels | enhancement |
| assignees | [] |
| createdAt | Jul 19, 2024, 6:09 PM |
| updatedAt | Jul 20, 2024, 2:05 PM |
| githubUrl | https://github.com/neomjs/neo/issues/5591 |
| author | tobiu |
| commentsCount | 4 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Jul 20, 2024, 2:03 PM |
model.Component: enhance 2way-bindings

I think the new syntax would be better unless the prior syntax enables flexibility in combining field values to produce a calculated value. Obviously, this calculation could be done in another way prior to the binding so this flexibility might not be necessary. One question about the new syntax seems unclear: How does it bind to a stock config like the "value" property of the TextField?

the properties (keys) inside the bind object are the names of the configs. for one way bindings, we do need the transformation function. using fat arrows is optional.

so, with the new syntax, I could do this?
bind: {
value: {twoWay: true, property: 'data.foo.bar.baz'}
},

I would like to close this ticket, since the first version is working fine.
You can test it inside Neo.examples.model.twoWay.
I did test the other approach a bit, but this one is complicated: we would need to use new Function('data', `data.${value.property}`)
inside createBindings(), but also adjust parseConfigs().
Some security issues and time consuming.
You are welcome to create a follow-up ticket though, in case you think it is important.
Right now, 2way only works in case the name of the config is exactly the same as the name of the bound data prop:
bind: { intlFormatDay: {twoWay: true, value: data => data.intlFormatDay}, weekStartDay : {twoWay: true, value: data => data.weekStartDay} },This was obviously not intentional.
We should evaluate if we want to keep the current syntax or modify it. 2way kind of enforces to only allow direct bindings and no field combinations, since we can not know how to transform back out of the box.
So we would either use the regex-parsing inside VMs or adjust the syntax. e.g.:
bind: { weekStartDay: {twoWay: true, property: 'data.foo.bar.baz'} },