player-ui / player

https://player-ui.github.io
MIT License
73 stars 47 forks source link

Ability to nest expressions #492

Closed KieranTH closed 3 months ago

KieranTH commented 3 months ago

Is your feature request related to a problem? Please describe.

It would be really nice if we could have the ability to nest expressions in each other. This is especially nice for when dealing with complex JSON structures in the data for Player.

An example of this would be:

value: "@[merge2Objects({{objA}}, @[parseObjectB({{objB}})]@)]@"

Currently that expression fails purely due to what seems like string splitting on the special characters, @, {{}} and [].

Describe the solution you'd like

For the string splitting logic to be aware of possible nested occurrences of special characters, and to deal with them appropriately. It should probably work "backwards" - Where the deepest expression is ran first, so that the returned instance of that expression can be fed into the parent expression - Unless the expression parser itself can deal with this is in the translation layer.

Cheers!

adierkens commented 3 months ago

Hey @KieranTH

This should actually be supported today (a good push for us to update the docs to make this clearer)

Once you're inside of an expression block (the contents wrapped by @[ ]@), you're free to use and nest any number of expression calls. In your example, it would be something like:

value: "@[ merge2Objects({{objA}}, parseObjectB({{objB}})) ]@"
KieranTH commented 3 months ago

Hey @KieranTH

This should actually be supported today (a good push for us to update the docs to make this clearer)

Once you're inside of an expression block (the contents wrapped by @[ ]@), you're free to use and nest any number of expression calls. In your example, it would be something like:

value: "@[ merge2Objects({{objA}}, parseObjectB({{objB}})) ]@"

That's amazing!

Feel free to close this issue in that case 😄

Great way of solving the issue too without having to repeat @[]@ instances!

Thanks