News for hackers. Stuff that matters.
Re:A little bit of plain JavaScript can do a lot by warent on Sunday June 21, 2020 @02:51AM (#23590360)
Its just a helper function to create an element, assign it some properties, and append children elements. Not very much unlike React in the API (emphasis on "interface") but of course the inner workings is as minimal as possible.
Re:A little bit of plain JavaScript can do a lot by areoform on Sunday June 21, 2020 @03:34AM (#23590493)
Could you explain how it does this?
Re:A little bit of plain JavaScript can do a lot by hexaga on Sunday June 21, 2020 @05:59AM (#23591059)
I don't know much js, but it seems fairly straightforward. Here's some comments:

    // create an element with 'tag'
    const elem = document.createElement(tag)

    // copy properties into the new element one at a time
    for (const k in props) {
        elem[k] = props[k]
    }

    // append child elements one at a time
    for (const kid of kids) {
        elem.appendChild(kid)
    }

    // and that's it
    return elem
Applied recursively, you can make dom elements with very little boilerplate.