[Ur] Data attributes

Sergey Mironov grrwlf at gmail.com
Fri Feb 21 02:12:33 EST 2014


Hi! +1. Ur/Web definitely needs better HTML5 support. I vote for the
second approach [<div data={("foo", "bar") :: nil}/>] since It looks
simpler.

First approach looks nice but I have not got use cases in my mind for
it (but I have little experience of writing HTML5). I think that it
would overuse the typechecker, since AFAIK the typechecker could
answer only simple type questions about HTML at the moment. What
guarantees do we usually want when we use data-* ? Do we  want to be
protected from repeating the same [data-foo] attribute twice?

I think that the whole task of supporting data-* attributes may be
much like the older task of supporting css classes, where Ur/Web
relies on special [css_class] data type and [<div
style={mystyle}>...</div>] syntax. Also, we have a way of adding
css_classes together and may write [<div style={css_classes mystyle1
(css_classes mystyle2 (css_null))} >...</div>] (sorry, I don't remeber
exact function names). This approach gives us only basic guarantees
from the typesystem but in practice looks like it is not a problem.

Are you working on writing a Bootstrap3 library? Do you have a public
repo to try?

Regards,
Sergey

2014-02-21 2:56 GMT+04:00 Patrick Hurst <phurst at mit.edu>:
> Any attribute whose name starts with 'data-' is valid on any HTML5
> element with any value (see
> <http://www.w3.org/html/wg/drafts/html/CR/dom.html> section 3.5.9). Some
> frameworks, such as Twitter Bootstrap 3, rely on the presence of these,
> but right now there's no easy built-in way to include them using Ur/Web
> XML literals.
>
> One approach would be to add a 'data' pseudotag, similar to the 'link'
> tag on <a> elements, whose value is a record all of whose values are
> strings; [<div data={{Foo = "bar"}}/>] would then be rendered as [<div
> data-foo="bar"></div>]. The downside of this is that it'd involve
> significant changes to the standard library type system, since the [tag]
> type constructor would then need a new field for the names of all the
> data- attributes.
>
> Another approach is to have the value of the 'data' tag be a list of
> tuples of strings; [<div data={("foo", "bar") :: nil}/>] would then be
> rendered as [<div data-foo="bar"></div>]. I think this would be less
> safe, but also significantly easier to implement.
>
> I e-mailed Adam about this and he suggested I take it to the list. What
> do you all think?
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur



More information about the Ur mailing list