LearnNewsExamplesServices
Frontmatter
id5591
titlemodel.Component: enhance 2way-bindings
stateClosed
labels
enhancement
assignees[]
createdAtJul 19, 2024, 6:09 PM
updatedAtJul 20, 2024, 2:05 PM
githubUrlhttps://github.com/neomjs/neo/issues/5591
authortobiu
commentsCount4
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 20, 2024, 2:03 PM

model.Component: enhance 2way-bindings

Closed v8.1.0 enhancement
tobiu
tobiu commented on Jul 19, 2024, 6:09 PM

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'}
        },
tobiu added the enhancement label on Jul 19, 2024, 6:09 PM
marklincoln
marklincoln Jul 19, 2024, 6:44 PM

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?

tobiu
tobiu Jul 19, 2024, 6:46 PM

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.

marklincoln
marklincoln Jul 19, 2024, 6:51 PM

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

tobiu referenced in commit 56d791d - "#5591 new testcase example" on Jul 20, 2024, 12:52 PM
tobiu referenced in commit 83af87d - "#5591 model.Component: 2way-bindings => working solution using the old syntax" on Jul 20, 2024, 1:07 PM
tobiu
tobiu Jul 20, 2024, 2:03 PM

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.

tobiu closed this issue on Jul 20, 2024, 2:03 PM