Replies: 3 comments 4 replies
-
Nice improvement indeed |
Beta Was this translation helpful? Give feedback.
-
Very interesting discussion! I will take a closer look and get back to you when I get a big chunk of time (maybe after the memorial long weekend). |
Beta Was this translation helpful? Give feedback.
-
The actually story is, I knew very little about modern front-end frameworks while developing VanJS. I heard of Vue.js, Angular by names (never knew what they really are), and I had seen some sample React programs, thus I knew a little bit about React at the concept level. jQuery is the only library that I had ever used while doing front-end programming. So my journey with VanJS started with my programming with Vanilla JavaScript while building personal tools. Thus initially, I was writing code like that: const anchorDom = document.createElement("a")
anchorDom.href = "https://vanjs.org"
anchorDom.appendChild(new Text("🍦 VanJS")) But soon I found this is quite verbose especially when the DOM structure becomes very complicated, thus I started to build some helper functions to help me write: a({href: "https://vanjs.org"}, "🍦 VanJS") instead. Thus this was the initial prototype of VanJS. I kept iterating the helper functions to make it more ergonomic, until it has been evolved to the current form. It worths to note that, the initial version of VanJS is a little bit hacky: providing tag functions by polluting the The mechanism of adding the reactivity part was discovered by this March. Before that I was using the ad-hoc approaches to support application-specific reactivity for the personal apps I built. Initially my thought was that reactivity was so hard that only complex framework like React can do it correctly. But during one night, when I was trying to think through the problem, I discovered a seemingly correct solution with just web standard API like Thus, if I was to summarize how VanJS was made, I would like to attribute its creation to "First Principles". Knowing so little about modern Front-End frameworks puts me into a quite unique position that is free from the influence of any modern frameworks. All what I was thinking was: given the problem, what is the shortest path to solve it with only web standard API available? It is quite funny that only after the public release of VanJS I started to know the existence of so many frameworks like SolidJS, MithrilJS, ArrowJS and so on and so forth, because I can always see comments like "Oh, this is quite similar to ...", "How do you compare VanJS with ..." So talking back to the SolidJS-style API. I never heard of SolidJS when VanJS was being developed. If I heard of it before, the design of VanJS might be influenced to another style. So looking at your examples: span({style: () =>`font-size: ${size}px; color: ${color};`},
" Hello 🍦VanJS") my understanding is it wouldn't work as both span({style: () =>`font-size: ${size()}px; color: ${color()};`},
" Hello 🍦VanJS") So, my general feeling about SolidJS-style API: I agree the code for complex binding is relative less verbose than VanJS. But there are also downsides, like making a function call to get the state values feels quite unnatural. Also, to be honest, I feel that the React-style state-hook API like: const [counter, setCounter] = useState(0) is quite counterintuitive. Beginners need spend significant amount of time the grasp the concept. In this regard, I feel that VanJS's state API is much better. While I agree that for complex bindings, VanJS code is slightly more verbose. This is a downside I have to admit. But the general philosophy of VanJS is to bind states directly to DOM node or DOM properties as much as possible, and only do complex binding when it's absolutely necessary. In all the sample apps I built with VanJS, the complex binding is only needed in sparse scenarios. In my personal opinion, VanJS's API choice is acceptable. But I definitely understand other people might hold different opinions. I totally admitted that for complex UI applications VanJS is not on par with React. I don't position VanJS as React's replacement or competitor. I am rational enough to recognize the fact. VanJS is just a project that I built with my personal time. There is no point it can compete with React which has hundred-billion-dollar companies like Meta's backing. The purpose of VanJS, is to solve the problem where other mainstream frameworks don't seem quite care to solve, which is: I know very little about front end programming. I have no comprehensive tools, nor I am familiar with them. How can I build a useful UI app within just a couple hours? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! 👋
VanJS is awesome. You get the big benefits of modern frameworks with simple JS primitives: a succinct way to compose html, reactive state, and a way to compose both into reusable components. I had thought about combining hyperscript and some simple version of signals (like in SolidJS), but VanJS takes this to the next level. It looks you created a more modern version of hyperscript and a really natural signal API using the
Proxy
object. I'm curious, were hyperscript and SolidJS inspirations here, or did you end up arriving to similar ideas naturally?In a lot of cases, VanJS really seems more ergonomic than modern frameworks. However, there was one thing that stuck out to me. The tutorial gives this example for derived state:
But have you considered the following API?
It seem like an improvement because 1. It's more concise and 2. users don't need to manually track and declare dependencies. This is exactly how derived state works in SolidJS. If you haven't already seen this pattern, Ryan Carniato explains how to build this signal API in building a reactive library from scratch.
Similarly,
van.bind
could get the same benefits. This:Could be simplified to:
It seems totally possible for VanJS to support this API, though I admit I may be missing something. If this seems interesting I'm happy to explore this more. If you aren't interested in this, that's OK too!
Beta Was this translation helpful? Give feedback.
All reactions