Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expressions: Allow for re-use of expressions #1177

Open
1 task
olemartinorg opened this issue May 22, 2023 · 0 comments
Open
1 task

Expressions: Allow for re-use of expressions #1177

olemartinorg opened this issue May 22, 2023 · 0 comments
Labels
area/logic related to logic/dynamics/expressions kind/feature-request New feature or request

Comments

@olemartinorg
Copy link
Contributor

olemartinorg commented May 22, 2023

We should allow for developers to re-use common expressions, thus allowing them to avoid copy-pasting functionality in the layout files. How we achieve this is up to those who should implement it, but my suggestion is below:

Suggested solution

We add a new file that can be configured on the top-level of each app, which contains a simple JSON object with function names as keys and expressions as values. Upon loading the app, app-frontend-react asks the backend for this file (if the feature is implemented there), and loads it.

Loading the file populates a user-provided set of functions into the expression engine. If any custom function conflicts with our internal function names, user expressions should always load the custom expression - but our own implementation should always run the hard coded expression. That way we should allow for forwards-compatibility in such a way that we can supply new functions without checking if any app already defines that function - a function call in an app would simply use the custom function and the app developer would need to rename it to start using ours. But in cases where our own engine calls other functions, that should not crash if a custom function has been provided.

New functionality needed

  • argv function, to fetch any arguments in a custom function and use them as parameters/manipulate them.

Example

This implements a custom function with the signature ["max", number, limit] which returns the input number, but limits it to limit.

{
  "max": [
    "if",
    ["greaterThan", ["argv", 0], ["argv", 1]],
    ["argv", 1],
    "else",
    ["argv", 0]
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logic related to logic/dynamics/expressions kind/feature-request New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant