Re: [cssom] CSS Value API

On Apr 21, 2010, at 9:45 PM, Anne van Kesteren wrote:

> On Thu, 22 Apr 2010 07:30:28 +0900, Ojan Vafai <ojan@chromium.org> wrote:
>> Also, I find the m and l accessors confusing. Can we just have a single
>> accessor for all types, e.g. v for value?
> 
> Consider a property 'foo' that takes two values and is therefore represented by a map. Consider then that CSS changes over time. The CSS WG decides that 'foo' will now be a comma-separated list. To remain backwards compatible it will need to expose both a map and a list. That is the reason I gave it two different accessors. I am open to other solutions.

OK; you asked for it. I will make a suggestion for an alternate solution, as I too find the l and m accessors to be less than obvious (especially since a lower case L looks a lot like a numeral 1 (in some fonts), an upper case i, and a pipe character). But please keep in mind that I am not a Jedi Master of JavaScript, so forgive me if what I suggest is actually stupid.

So, as I understand the backwards compatibility story, 'foo.m' would continue to provide a map array-like object in your example, even though it was really coming from 'foo.l[0].m'. Is that correct, so far?

It seems to me that this could be made simpler by getting rid of the m attribute and just have that available on the property object. And spell out "list" for clarity. So, for instance (assume also the first component property is called "snork" and the second one is "width"):

myEl.style.foo // --> "bar 2px, baz 3px, quux 4px"
myEl.style.foo[0] // --> "bar"
myEl.style.foo.snork // --> "bar"
myEl.style.foo.width.px // --> 2
myEl.style.foo.list[0] // coerced to string --> "bar 2px"
myEl.style.foo.list[0][0] // --> "bar"
myEl.style.foo.list[0].snork // --> "bar"
myEl.style.foo.list[0].width.px // --> 2
myEl.style.foo.list[1] // coerced to string --> "baz 3px"
myEl.style.foo.list[1][0] // --> "baz"
myEl.style.foo.list[1].snork // --> "baz"
myEl.style.foo.list[1].width.px // --> 3

Alternately, you could get rid of ".list", assume everything is a list, and just always include the "[0]" for things that aren't lists. Then you'd have this:

myEl.style.foo // --> "bar 2px, baz 3px, quux 4px"
myEl.style.foo[0] // coerced to string --> "bar 2px"
myEl.style.foo[0][0] // --> "bar"
myEl.style.foo[0].snork // --> "bar"
myEl.style.foo[0].width.px // --> 2
myEl.style.foo[1] // coerced to string --> "baz 3px"
myEl.style.foo[1][0] // --> "baz"
myEl.style.foo[1].snork // --> "baz"
myEl.style.foo[1].width.px // --> 3

Received on Thursday, 22 April 2010 17:26:22 UTC