gulp-cjsx icon indicating copy to clipboard operation
gulp-cjsx copied to clipboard

Spread variables to elements, i.e. {...{var1, var2}}

Open danschumann opened this issue 8 years ago • 1 comments

In coffeescript you can make an object like this

myVar = 10
otherVar = 20
object = {myVar, otherVar}

# object == {myVar: myVar, otherVar: otherVar}

I would love to be able to pass properties to elements this way


<Element {myVar, otherVar} />

# same as <Element myVar={myVar} otherVar={otherVar} />

The best way I can seem to inline it currently (without writing var names twice ):

<div>
  {props = {myVar, otherVar}; null}
  <canvas {...props} />
</div>

This doesn't work

<canvas {...({myVar,otherVar})} />
<canvas {...{myVar,otherVar}} />
#etc

Heck, if you were ambitious, you could even do

myOb =
  foo: 'bar'
  quz: 'quack'

<Element {myVar, ...myOb, otherVar} />

# outputs <Element myVar={myVar} foo={myOb.foo} quz={myOb.quz} otherVar={otherVar} />

Thoughts?

Great lib btw

danschumann avatar Oct 28 '16 19:10 danschumann

This library is just a thin shell over the actual cjsx parser so it can work with gulp. I'd imagine this issue should be opened on the repo for the actual cjsx parser.

Also, I don't user CoffeeScript anymore, I'll take pull requests but I won't actively work to fix this myself.

mtscout6 avatar Nov 10 '16 21:11 mtscout6