question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What's the correct use of a resolver?

See original GitHub issue

Hi, I want to have a IMC field automatically computed with the value of two other fields POIDS and TAILLE, and I want this field to be read only.

For that sake I use the following (simplified) schema:

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": "object",
  "properties": {
    "TAILLE_CLI":{
      "title": "Taille",
      "type": "number",
      "description": "Entrez la taille en mètre. par exemple: 1.75"
    },
    "POIDS_CLI":{
      "title": "Poids",
      "type": "number",
      "description": "Entrez le poids en Kg. par exemple: 75.5"
    },
    "IMC_CLI":{
      "title": "IMC",
      "readOnly": true,
      "type": "number",
      "description": "Indice de masse corporelle = poids/taille²",
      "dependsOn": ["POIDS_CLI", "TAILLE_CLI"]
    }
  }
}

and the following (simplified) resolver:

    // return the resolved schema given the specific business rule
    resolver : function(names, data, cb) {
        var schemas = [];
        var sch = new Object();
        var current = currentSchema.properties;
        switch(names[0]) {
            case "$.IMC_CLI":
                sch = JSON.parse(JSON.stringify(current.IMC_CLI));
                if(data.POIDS_CLI !== undefined && data.TAILLE_CLI !== undefined) {
                    sch.enum = [data.POIDS_CLI / (data.TAILLE_CLI * data.TAILLE_CLI),""];
                    sch.readOnly = true;
                }
                break;
        }
        schemas[names] = sch;
        cb(schemas);
    }

If I entirely clone ‘current.IMC_CLI’ into ‘sch’ with sch = JSON.parse(JSON.stringify(current.IMC_CLI)); I get the following error: Uncaught TypeError: Cannot read property ‘type’ of undefined at render (brutusin-json-forms.js:1210) at renderers.object (brutusin-json-forms.js:598) at render (brutusin-json-forms.js:1224) at Object.obj.render (brutusin-json-forms.js:831) at client.html:25 If I comment out sch = JSON.parse(JSON.stringify(current.IMC_CLI)); My IMC_CLI field is never visible

The only way I found to have my IMC_CLI field behaving correctly is to copy member by member ‘current’ into ‘sch’ like this:

            case "$.IMC_CLI":
                sch.type = current.IMC_CLI.type;
                sch.title = current.IMC_CLI.title;
                sch.description = current.IMC_CLI.description;
                sch.required = current.IMC_CLI.required;
                sch.readOnly = current.IMC_CLI.readOnly;
                if(data.POIDS_CLI !== undefined && data.TAILLE_CLI !== undefined) {
                    sch.required = true;
                    sch.enum = [data.POIDS_CLI / (data.TAILLE_CLI * data.TAILLE_CLI),""];
                    sch.readOnly = true;
                }
                break;

Is there a simpler way to return a fully filled object from resolver without having to copy each member, which is error prone?

Note: when cloning the object with the JSON stringify/parse method I see a strange behaviour in the last for loop of populateSchemaMap() function. After a few series of calls, the ‘name’ parameter of the function becomes “$.IMC_CLI,$.IMC_CLI” instead of “$.IMC_CLI”. I assume this is due to the returned value of my resolver.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
idelvallcommented, Apr 20, 2017

be aware that by using the simple assignment your are modifying the original schema, since you have two references to the same instance

1reaction
joguiMultimediacommented, Apr 20, 2017

Ok much simpler test. Updating simple example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers - What Are They and How Do They Work? | Dynapar
Resolvers, known as motor resolvers, are commonly used in servo motor feedback applications due to their good performance in high temperature environments.
Read more >
Resolvers - How Do They Work? (A Guide) - Celera Motion
A resolver is an electrical transformer used to measure the angle of rotation. Many resolvers look somewhat like an electric motor comprising of...
Read more >
Tutorial: What Is A Resolver? - AMCI
A resolver is a rotary transformer where the magnitude of the energy through the resolver windings varies sinusoidally as the shaft rotates. A...
Read more >
Resolver (electrical) - Wikipedia
A resolver is a type of rotary electrical transformer used for measuring degrees of rotation. It is considered an analog device, and has...
Read more >
Basics: Resolver - Function and use in an electric motor
The Resolver is a measuring instrument that is used to determine the angular position and speed of a rotor. It is a particularly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found