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

Create JSON structures from conditions #23

Open
sylvainhalle opened this issue Mar 30, 2021 · 1 comment
Open

Create JSON structures from conditions #23

sylvainhalle opened this issue Mar 30, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@sylvainhalle
Copy link
Contributor

The reverse of #22 (i.e. the serialization process). Not necessary at the moment, but could be useful in the future.

@sylvainhalle sylvainhalle added the enhancement New feature or request label Mar 30, 2021
@EmilePerron
Copy link
Collaborator

As discussed, here is an example.
Assuming a method named toJson() on the AbstractFunction class, the following snippet:

var quantifier = new UniversalQuantifier(
    "$x",
    new FindBySelector("#h2"),
    new ComposedFunction(
        new GreaterThan(),
        new ComposedFunction(new Opacity(), "$x"),
        0.9
    )
);
var json = quantifier.toJson();

console.log(json);

should result in the following serialization (JSON):

{
   "name": "UniversalQuantifier",
   "contents": [
       "$x",
       {
           "name": "FindBySelector",
           "contents": [
               "#h2"
           ]
       },
       {
           "name": "ComposedFunction",
           "contents": [
               {
                   "name": "GreaterThan",
                   "contents": []
               },
               {
                   "name": "ComposedFunction",
                   "contents": [
                       {
                           "name": "Opacity",
                           "contents": []
                       },
                       "$x"
                   ]
               },
               0.9
           ]
       }       
   ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants