LearnNewsExamplesServices
Frontmatter
id4648
titlemodel.Component: resolveFormulas() => we need a smarter check for affected keys
stateClosed
labels
enhancementstale
assigneesDinkh
createdAtAug 4, 2023, 10:27 PM
updatedAtSep 13, 2024, 4:29 AM
githubUrlhttps://github.com/neomjs/neo/issues/4648
authortobiu
commentsCount3
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtSep 13, 2024, 4:29 AM

model.Component: resolveFormulas() => we need a smarter check for affected keys

Closed v8.1.0 enhancementstale
tobiu
tobiu commented on Aug 4, 2023, 10:27 PM

the code:

if (!initialRun) {
    affectFormula = Object.values(value.bind).includes(data.key)
}

does assume that bound values are string based, which they are not. it does not honor fn calls or data.property combinations.

examples of bindings on component level:

bind: {
    a: data => data.a // data.a is inside a fn body
    b: data => data.a + data.b,
    c: data => MyUtil.parse(data.a + data.b),
    d: data => `Hello ${data.button2Text} ${1+2} ${data.button1Text + data.button2Text}` // template literal
},

One question: do you want to support formulas which use data properties from parent VMs? Asking since this is already in place for default component based bindings (which are formulas in their own way).

To understand the parsing of our bindings, follow the chain: createBindings() => https://github.com/neomjs/neo/blob/dev/src/model/Component.mjs#L227 createBindingByFormatter() => https://github.com/neomjs/neo/blob/dev/src/model/Component.mjs#L215 getFormatterVariables() => https://github.com/neomjs/neo/blob/dev/src/model/Component.mjs#L368

Especially the last one is crucial, since it extracts data properties from fn bodies (which are strings) via regexes. You want to use it for formulas as well :)

tobiu added the enhancement label on Aug 4, 2023, 10:27 PM
tobiu assigned to @Dinkh on Aug 4, 2023, 10:27 PM
tobiu
tobiu Aug 5, 2023, 12:57 AM

i am still not sure if i can see the benefit of having formulas in the first place, since we can do any kind of complex bindings directly on component level.

the only reason that comes to my mind might be to "cache" binding values in case they get long. but, in this case, you can just use helper fns on cmp level. like: c: data => MyUtil.parse(data.a + data.b).

so i think if we want to keep vm based formulas, they have to be on the same level as default bindings, plus cmps must be able to actually use them (this part seems not to be implemented). like: e: 'formula.aPlusB'.

can you please shed some light into this?

@github-actions - 2024-08-29T02:26:52Z

This issue is stale because it has been open for 90 days with no activity.

  • 2024-08-29T02:26:52Z @github-actions added the stale label

@github-actions - 2024-09-13T02:29:22Z

This issue was closed because it has been inactive for 14 days since being marked as stale.

  • 2024-09-13T02:29:23Z @github-actions closed this issue