4 ms·
Neat project! I wanted to leave some feedback for the author. If you just want an interface for building up an AST using composition, you can do this without R
by JasonSage 7y ago
Neat project! I wanted to leave some feedback for the author.
If you just want an interface for building up an AST using composition, you can do this without React. You can even continue to use JSX—it's as simple as having a function definition to create AST primitives and have a JSX pragma that calls into it.
What React is excellent at is taking two trees and finding a set of mutations to transform the nodes from the first tree to the second—with utter disregard to how those trees came to be. That's what the renderer provides—the set of operations that can be performed on nodes.
I don't see how the actual React part can be used here. Even the suggested uses are all single-pass operations where this diffing will never come into play.
That said, to me this project (in its current state and with the goals expressed) would be so much simpler and more efficient written as a JSX pragma, without the React part.
Maybe there's more to the React functionality in this project that I'm missing. I don't want to discourage the author from doing something with React for this project—there's many directions you could take this that could make excellent use of React.
- tolmasky 7y agoFunnily enough, I did this as a quick example for my generic-JSX blog post a few years ago (http://tolmasky.com/2016/03/24/generalizing-jsx/ http://tolmasky.com/2016/03/24/generalizing-jsx/). You can see it here, it creates JSX definitions from Babel AST definitions, so you end up with Babel/MDN compatible trees: https://runkit.com/tolmasky/generic-jsx-for-babel-javascript-ast https://runkit.com/tolmasky/generic-jsx-for-babel-javascript...
- codejamninja 7y agoGreat feedback. The points you make are good. Listed below are the reasons I chose to go with react. 1. I'm getting my feet wet with React rendering (I will be building a full react renderer in the future for another project) 2. It may be useful in the future for dynamic code editing (not sure but a possible use case) 3. Though react really shines in the render lifecycle, it does provide a nice pattern for building components. I see this project being used as a way to componentize composable code generators and snippets.
- JasonSage 7y ago> I see this project being used as a way to componentize composable code generators and snippets. You can do this without React though, using only JSX. I've implemented this pattern in a library (not open source yet) that builds in a lot of these composition patterns (pass children as child or prop, etc) so that you can use it in familiar ways while still just being JSX.