Martijn Faassen
unread,Jun 24, 2013, 10:06:34 AM6/24/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to polymer-dev
Hi there,
A common pattern is to include a class on an element if some condition
is true. I can't find a shorter way to express this in MDV than this:
<template if="{{active}}">
<li class="active">Foo</li>
</template>
<template if="{{!active}}">
<li>Foo</li>
</template>
(not sure about "!active" as the correct spelling of not active)
Unless I'm missing something conditional attributes don't seem to
cover this case, as I wouldn't be able to express the existence of a
class, just the existence of an attribute.
So this is rather a lot of repetition, especially if you have other
things going on too.
In Obviel Template I got around this by allowing a callback into
JavaScript that set things up. In hypothetical MDV terms:
<li mdv-call="myfunc">Foo</li>
var myfunc = function(element, bound) {
if (bound.active) {
element.classList.add("active");
}
}
This is quite powerful, but might run into all sorts of issues as
myfunc can depend on arbitrary state, so MDV won't know whether things
need to be updated or not. With sufficient extra metadata something
like this could be made to work, though, I imagine.
Another pattern I explored is something like this:
<li><template if="{{active}}"><mdv-attr
name="class">active</mdv-attr></template>Foo</li>
this allows you to apply conditional logic directly to attributes. But
this has a serious limitation: it won't work for elements which don't
allow such element content, such as input, img and textarea.
Does anyone have something better in mind? Or again, perhaps I missed something.
Regards,
Martijn