Re:Generalizing JSX: Delivering on the Dream of Curried Name...
by tolmasky on Thursday March 24, 2016 @04:20PM
(#11356106)
Yeah the use of eval is purely to get it working today. The ideal would be to just change the JSX parser to place whatever is in the JSX tag directly. That would also give you arbitrary expressions:
<memoize(f) key = "value"/>
<compose(f,g) key = "value" />
If you look at the implementation in the repo, you'll see its actually a little more complex than just eval now (since JSX will pass the actual reference when the tag name starts with a capital letter), but again this was solely to provide something that people could use with their existing Babel implementations and a simple require.
Re:Generalizing JSX: Delivering on the Dream of Curried Name...
by kbenson on Thursday March 24, 2016 @05:44PM
(#11356710)
Couldn't you get around using eval by just use an object and register methods on it, instead of global functions, essentially using the object as a namespace? Instead of
/* @jsx ((a,b)=>(eval(a)(b))) */
You would have /* @jsx ((a,b)=>(MyJSX[a](b))) */
And then just build your functions on top of the MyJSX object?
Re:Generalizing JSX: Delivering on the Dream of Curried Name...
by WorldMaker on Thursday March 24, 2016 @06:14PM
(#11356912)
Yep, that's essentially where I was leading.
I think my only criticism of the current approach in the linked GitHub repo [1] is the use of `eval`, as that could make it tough to utilize in low security/sandboxed environments such as mobile apps and CSP-controlled sites.
I'll save attempting an actual code exercise for later, but my first thought was maybe using JS implicit `this` to your advantage (even while trying to stray away from classes) and using `this[functionName]` to index into it. (You'd still have security concerns with `this` defaulting to `window` or `global`, but you'd avoid the need for `eval` and you can take advantage of the depth of abilities of constructor functions and ES2015 class syntax.)
[1] https://github.com/tolmasky/generic-jsx