Re: [css-houdini-drafts] [css-typed-om]: There's no nice way to represent CSSUnparsedValue as a "list-plus" style object.

The CSS Working Group just discussed Arraylike, and agreed to the following resolutions:

```
RESOLVED: Option 2- Use iterable
```

<details><summary>The full IRC log of that discussion</summary>

```
<fantasai> Topic: Arraylike
<TabAtkins> GitHub Topic: https://github.com/w3c/css-houdini-drafts/issues/239
<TabAtkins> https://docs.google.com/presentation/d/1pXoJ4vqRfjww7xJ8DYTYk8LBu0kGyGyg0yZm88w8xBw/edit?usp=sharing
<fantasai> TabAtkins: Couple interfaces in typed OM, e.g. CSSUnparsedValue, CSSTransformValue, that are just sequences of other values. They have other extra data, e.g. transform has an equivalent matrix
<fantasai> TabAtkins: Bat at their core,they are sequences of values. SO they really want to b arrays
<fantasai> TabAtkins: Really want to use array notations
<fantasai> TabAtkins: But making something arraylike, only way is to use Proxies, which are slow and not desired by impelmenters.
<fantasai> TabAtkins: annoying cus maps adn sets are easily faked
<fantasai> TabAtkins: WebIDL is also broken, can't even do iterbles without invoking Proxies
<fantasai> TabAtkins: WebIDL is doing something vey stupid for bad reasons. (I'm gonna be really judgemental here.)
<fantasai> TabAtkins: Wnated to go over these issues
<fantasai> SimonSapin: Can we fix WebIDl?
<fantasai> TabAtkins: First option is suck it up, use LegacyArrayClass. Invokes Proxy. Not great.
<fantasai> TabAtkins: It also means tha tany Array mentods that return an array, return a real array, not an instance of our arraylike.
<fantasai> till: That shouldn't be ture anymore with species
<fantasai> TabAtkins: That's option 3 :)
<fantasai> TabAtkins: I don't want ot do Option 1, but it is a possiblity
<fantasai> TabAtkins: Option 2 is Use iterable
<shane> Not an array, but can be turned into one: let arr = [...cssThing]
<shane> As written today, would still invoke Proxy; it’s written to require indexed properties. Totally fixable, just hasn’t been fixed yet in WebIDL.
<shane> (kv-iterator doesn’t act badly like this. It can be fixed!)
<shane> Probably good enough, at least as a first step.
<fantasai> TabAtkins: This lets you iterate in a for loop, or to cast things itno an array
<fantasai> TabAtkins: It's okay as a first step
<fantasai> TabAtkins: Fairly easy to eget to
<fantasai> TabAtkins: Problem is WebIDL value iterators, which is what we'd use here, still requires Proxy
<fantasai> TabAtkins: ....
<fantasai> TabAtkins: So WebIDL needs to be fixed
<fantasai> TabAtkins: This would be okay
<fantasai> TabAtkins: Coudl also hack around key-value iterator. Doesn't have the problems. But it's hack.
<fantasai> TabAtkins: This is a possible solution, particularly in ES6 casting is easy
<fantasai> TabAtkins: Option 3 is desirable one which is ES spec now has proper sublcassable arrays
<fantasai> TabAtkins: Similar to previous step, but it's a real Array
<fantasai> TabAtkins: Will also return the correct subclass from Array methods
<fantasai> ChrisL: Which version of ES spec did that come from, and can you compile this down to ES6?
<fantasai> till: It's ES6 and it is implemented in all engines
<fantasai> TabAtkins: Not fixed in WebIDL yet
<fantasai> TabAtkins: Only problem with this is tha tyou still can't intercept a set operation, like you can with maps
<fantasai> TabAtkins: So people can put random crap in your interface
<fantasai> TabAtkins: e.g. CSSUnparsedArray is suppoed to only have strings and ??
<fantasai> TabAtkins: Not sure what to do with that, do we throw when you add something that's invalid?
<fantasai> TabAtkins: Most of the time you can sanitize at  ...
<fantasai> leaverou: If the issue is that people can mess with your types, that's just how JS works
<fantasai> TabAtkins: In maplike, in calc(), because it has an impl of set method, can do type checking and tell you if you're doing somehting wrong right away
<fantasai> TabAtkins: If you're setting an aributary object to px key, will thorw, becaues not a number
<fantasai> TabAtkins: Doesn't look corect, and then later when you're setting into a property map, break down
<fantasai> leaverou: That's their own fault
<fantasai> TabAtkins: But we still have to handle corretness
<fantasai> TabAtkins: And we'd have to handle it via checking every set, iterating over it, even in cases where you haven't done anything wrong, which is more computation than is required.
<fantasai> TabAtkins: If you're strict at the start, then we don't have to do such extra checks
<fantasai> till: I think you fundamentally want Proxies ot implement that
<fantasai> ...
<TabAtkins> AWB had a proposal to let you hook the [] syntax, but that's never gone anywhere. :(
<fantasai> shane: At least with proposal 2 the only time we need to check correctness is on construction, and that is very ...
<fantasai> shane: We wouldn't be in stuation where every time we need to use contents we typecheck them
<fantasai> TabAtkins: So I think we should go with option 2 for now, and then in future, go into Array subclassing
<fantasai> Rossen: What would prevent us from going to Array subclassing in the future?
<fantasai> TabAtkins: Only if you're doing exotic checkes on whethe rit's an array or not
<fantasai> TabAtkins: If just iterating over it, won't notice the difference
<fantasai> till: The performance on Proxies might not be tha tmuch of a problem going forward
<fantasai> till: Engines are doing pretty good optmizations nowadays
<fantasai> till: If all you hve is a set hook, then should be optimizable
<fantasai> TabAtkins: I was told that's not the case
<fantasai> iank_: I was told we're not goint to b able to make Proxies fast anytime soon
<fantasai> till: in the general case, that's true, but htis isn't the general case
<fantasai> TabAtkins: If good news comes out, ok to change, but for now would go with option 2
<fantasai> Rossen: So you're proposing to go with option 2
<fantasai> Rossen: Any objections?
<fantasai> Rossen: Anyone for option 3 at this point?
<fantasai> RESOLVED: Option 2- Use iterable
<shane> https://docs.google.com/document/d/1NA020gku-tgEHMGK_8xkB6Ksfpd8ieL4z9jFoGchzbA/edit
```
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/239#issuecomment-294662121 using your GitHub account

Received on Tuesday, 18 April 2017 03:13:06 UTC