Re: Simplifying element creation

On Sun, Nov 13, 2011 at 9:06 PM, Dominic Cooney <dominicc@chromium.org>wrote:

> On Sun, Nov 13, 2011 at 7:41 PM, Ryosuke Niwa <rniwa@webkit.org> wrote:
>>
>>  to
>>     var table = Element.create('table', {}, [Element.create('tbody')]);
>> ...
>>     for (var i = 0; i < labels.length; i++) {
>>         table.childNodes[0].append(
>>             Element.create('tr', {}, [
>>                 Element.create('td', {}, [labels[i]]),
>>                 Element.create('td', {}, [
>>                     Element.create('span', {'class': 'bar', 'style':
>> 'width: ' + <same expression> + '%'}),
>>                     Element.create('span', {'class': 'value-container'},
>> [values[i]])])
>>                 ])
>>         );
>>     }
>>     element.appendChild(table);
>>
>> My only complain will be that I had to serialize style attribute. I want
>> to be able to do:
>> Element.create('span', {'class': 'bar', 'style': {'width': <same
>> expression> + '%'}})
>> instead.
>>
>
> Instead of carving out an exception for 'style', could we optimistically
> assume that CSSOM will specify a convenient way to create CSSRule instances
> from JavaScript, and allow style: e where e results in a CSSRule?
>

You mean CSSStyleDeclaration? That's an interesting idea.

- Ryosuke

Received on Tuesday, 15 November 2011 00:17:17 UTC