Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If I was making this kind of mini framework instead of this

    a({href: "https://vanjs.org/"}, "VanJS")
I would have gone with this shorter way

   a("VanJS").href("https://vanjs.org/")
And make it chainable and allow class names as second argument as in

    a("About us", ".big.red").href("/about.html").target("_blank")


Chaining is very... 2010? Mainly because it's used().to().make().awful().APIs().like().this(). It got popular then seems to have died out.

href() isn't a function name. One doesn't 'href()' anything.


You know what promises are right?


Yes I do.

Do you use JS or TS currently? We've had async/await since ES2017, it's supported everywhere you want, and there's no reason to see .then() chains anymore outside jokes regarding early 2000's film classic "Dude, Where's My Car?".

Pasting some code and cutting out the boring bits:

  const transaction = await makeTransaction(...);
  const signature = await sendAndConfirmTransaction(...);
  const tokenAccountsByOwner = await getTokenAccountsByOwner(...);
Even back when .then() chaining was used: chaining only existed because that was the only way we had to handle promises, rather than because it was a desirable syntax.


Why would you be so snarky in your answer? Always better to be humble and assume you might be wrong. In this case you are: Nobody chains promises anymore.


Tag functions being implemented with a Proxy (https://vanjs.org/tutorial#api-tags) could make that a little cumbersome, and would break the abstraction that `div(...)` just returns an HTMLDivElement you can do whatever you want with.


Yeah, plus I realized after posting that for nesting children it would mean having the properties at the end, not very dev-friendly, maybe the way this lib does it is the best way (without JSX or anything like that)


I think the way it's done is correct, an object passed as a parameter with key value pairs for attributes seems a lot more logical.


Maybe, but I bet this way would be slightly faster, because the library wouldn't have to loop through keys if they write functions for all the most common attributes (href, rel, className, type, etc)


Here's one for React:

https://github.com/jehna/nosx




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: