[Ur] Ur/Web -> JavaScript objects

Mark Clements mark.clements at ki.se
Sun Oct 6 17:45:50 EDT 2019


One aspect that I appreciate about Ur/Web is that the xml tags define keys and types that can /potentially/ be included in a tag - that is, a tag does but not need to include all of the keys.

In defining an FFI to a JavaScript library such as Chart.js, config options may be defined in terms of (nested) JavaScript objects with a range of potential keys/fields. Analogous to the xml tags, is there any way to define a record type in Ur/Web that potentially includes a subset of fields? As an example, a Chart.js config object in JavaScript could be:

val config = {
    type: 'bar',
    data: {
        labels: ['Red', 'Blue'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
}

with other keys not specified. The equivalent data in Ur/Web could be:

val config = {
    type = 'bar',
    data = {
        labels = 'Red' :: 'Blue' :: []
        datasets=  {
            label= '# of Votes',
            data= 12 :: 19 :: [],
            borderWidth = 1
        } :: []
    },
    options= {
        scales= {
            yAxes= {
                ticks= {
                    beginAtZero= True
                }
            } :: []
        }
    }
}

with a config type that includes these and other fields. (For this example, I realise that Ur/Web lists would need to be mapped to JavaScript arrays, while the 'type' and 'options' fields are expressed more simply as scalars or nested records.)

Are such "subset" record types possible in Ur/Web? The alternative would be to write many FFI functions to change the individual config parameters.

Sincerely, Mark.



När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://ki.se/medarbetare/integritetsskyddspolicy>.


Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20191006/d4116d08/attachment.html>


More information about the Ur mailing list