gulp-cjsx
gulp-cjsx copied to clipboard
Spread variables to elements, i.e. {...{var1, var2}}
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
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.