Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

How to evaluate string encoded conditions from an API call? #185

Answered by logaretm
datenspast asked this question in Q&A
Discussion options

You must be logged in to vote

I would follow @marina-mosti advice and avoid using Function.

The concerns also include sending untranspiled code so if an engineer used new/unsupported syntax in some browsers. Also, it could send malformed functions, either invalid JavaScript functions or functions with their return type that isn't a boolean (common with && and ||).

I would recommend going to a harder path where you explicitly define what kind of conditions possible via JSON, for example, I did something like this a while back:

{
  "model": "area",
  "type": "integer",
  "label": "What is the size of the system?",
  "when": { "field": "size_specification", "eq": "By area (m2)" }
}

Or if you are a fan of tuples:

{
  "model"

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@datenspast
Comment options

@marina-mosti
Comment options

Comment options

You must be logged in to vote
2 replies
@datenspast
Comment options

@marina-mosti
Comment options

Answer selected by datenspast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants