3 ms·
Author of the post here, yeah for the admin tooling that I derived this from I actually do use "components" (functions that turn javascript objects from an API
by xena 5y ago
Author of the post here, yeah for the admin tooling that I derived this from I actually do use "components" (functions that turn javascript objects from an API into HTML elements), but the real reason I discovered this was because I wanted to do it in a way that my Haskell and Rust-ruined brain could grok. I have a hard time with React's reverse PHP stuff but have no problem translating what I can conceptualize the DOM as in my mind into Javascript syntax using this (admittedly clunky) set of wrappers. Consider code like this:
let content = div({}, [
h3(feed.title),
ul(feed.items.map(item => li([ahref(item.url, item.title)])))
]);
This kind of stuff is way easier for me to deal with than the equivalent in JSX. I don't know why, but It Works For Me :tm:. It also has the advantage of not requiring a separate build step so you can just slap it into a Go binary with a go:embed directive and you're off to the races.
Plus as far as I understand it's fairly idiomatic for people to reinvent their own JavaScript frameworks for when they need something between JQuery and React. Xeact (zi-act) is designed to fill that gap. Serve with laundry sauce.
- gorgoiler 5y agoYou might be interested to know that in the alternate universe of Phabricator — the magnum opus of a PHP codebase that is the fourth cousin twice removed of Facebook’s internal PHP stack — there was a function not unlike the one you describe: https://github.com/phacility/libphutil/blob/034cf7cc39940b935e83923dbb1bacbcfe645a85/src/markup/render.php#L24 https://github.com/phacility/libphutil/blob/034cf7cc39940b93... It’s verbose but I learned a lot from it. For example, returning a more specific type than String can eliminate a large class of security / escaping bugs.