react-future icon indicating copy to clipboard operation
react-future copied to clipboard

Use class list and implicit ... identifier

Open sebmarkbage opened this issue 11 years ago • 4 comments
trafficstars

className : string -> classList : array

Objects and arrays could use an implicit ... identifier for deep updates. It's not yet clear how a deep update strategy would work in post-ES7 but this could be one way.

sebmarkbage avatar Jun 10 '14 02:06 sebmarkbage

What does {...a, ...b, classList: [..., 'green']} destructure into?

sophiebits avatar Jun 12 '14 23:06 sophiebits

I assume you mean desugar in the context of an object initializer (as opposed to a destructuring statement).

This is not real syntax and not yet part of the ES7 proposal. In this hypothetical proposal, it would desugar to the following ES6:

(
temp = Object.assign({}, a, b),
temp.classList = [...temp.classList, 'green'],
temp
)

sebmarkbage avatar Jun 12 '14 23:06 sebmarkbage

Sorry, yes – an object initializer. Thanks.

sophiebits avatar Jun 12 '14 23:06 sophiebits

I'm also for supporting array in classList.

Initially I was for adding array support in className, but I am now aware of the problems that can occur in code expecting className to be a string, and getting an array instead.

So I think a better solution would be the proposed classList property, which could then deprecate the className property. Under the hood, whenever React detects some value in className, it should both warn about deprecation and also copy the value in classList. A benefit of this would also be popularizing the lesser known/used classList dom method.

radubrehar avatar Oct 04 '14 05:10 radubrehar