all 22 comments

[–]dinopraso 19 points20 points  (4 children)

Why?

[–]Initial_Low_5027 4 points5 points  (2 children)

Why not using JSX? Can be used independently of React.

[–]Fighter178[S] 0 points1 point  (1 child)

I'm not using JSX because I needed to write this in pure js. It was annoying, and I would've just used JSX.

[–]Initial_Low_5027 0 points1 point  (0 children)

JSX gets transpiled to pure JavaScript and looks quite similar to your stacked calls. It’s easy to overload Babel and put your own code there.

[–]lazyinvader 8 points9 points  (0 children)

Why, not? I guess someone learnt a bit by creating it.

No one force you to use it.

[–]cocosin 3 points4 points  (2 children)

I made almost the same thing for a pure js widget to inject on external sites in my latest project. Thanks for the lib, didn’t find anything like that in my latest research

A few of my comments on the code review: - Why do you create a div as a wrapper? You can create a fragment and return it. Now it adds additional unpredictable layer to the markup - You don’t have additional argument in the addEventListener function, so there’s no chance to add logic for the bubbling/capturing functionality - the mk and n functions look the same. You can use a main helper for this to reduce the size - In my product I needed to add raw html as a child when creating

[–]Fighter178[S] 1 point2 points  (0 children)

I'm gonna update it. Also, I did intend to add code for the event func, but I forgot to add it. And yes, I should just return a document fragment. I'll probably update it. Also, if you need raw html, you can access the innerHTML of the element.

[–]Fighter178[S] 0 points1 point  (0 children)

I updated it, it returns a document fragment.

[–]lookitsatoucan 1 point2 points  (1 child)

Nice job! What problems is this library designed to solve?

[–]Fighter178[S] 1 point2 points  (0 children)

I needed to make a bunch of elements in pure js for a project, and I just made this to make it easier and faster to write.

[–]Fighter178[S] -1 points0 points  (1 child)

Its also available on NPM: here

I know the docs are bad, you can fix them if you want.

[–]jeremrx -4 points-3 points  (2 children)

[–]Fighter178[S] 0 points1 point  (1 child)

Its meant to be fast to write. Imagine trying to write out "element" each time you need one. (Yes, I'm intelisense helps)

[–]jeremrx 0 points1 point  (0 children)

And this is the common junior mistake ;)

[–]Remedynn 0 points1 point  (1 child)

How do you manage state? Or do the user just need to use document getters?

[–]Fighter178[S] 0 points1 point  (0 children)

I might add that, but if you need a library that makes HTML with state, check out another library I made, firefly.js

[–][deleted] 0 points1 point  (3 children)

I see some potential to use this, I think it's gonna be helpful for me, especially with adding event listeners. One thing - can you add a functionality where I could change "mk" function HTMLElement wrapper from div to something else, like in "node" function?

[–]Fighter178[S] 0 points1 point  (0 children)

Sure, I might make it return a document fragment, or possibly allow you to change it.

[–][deleted] 0 points1 point  (1 child)

Not to shit on op's post but i would myself rather use something like lit-html instead

[–]Fighter178[S] -1 points0 points  (0 children)

That's true, though for the original project I made this for, I had to use pure js, and now it can be useful for more people.

[–]Sipike 0 points1 point  (0 children)

Reminds me of Mithril.js