1.4.0: API simplification (less is more) #280
Replies: 3 comments 7 replies
-
|
There is no change in the implementation of |
Beta Was this translation helpful? Give feedback.
-
|
@Tao-VanJS appreciate the work, but releasing breaking changes with minor version can be problematic. If that's the practice for vanjs moving forward, I suggest mentioning it in the |
Beta Was this translation helpful? Give feedback.
-
|
van.val was rarely used? Seriously? UPD: |
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.
-
Hi fellow VanJSers,
I'm happy to announce the release of VanJS
1.4.0. 🎉🎉🎉Since its first public debut last May, VanJS maintains its goal of reducing the entry barrier of UI programming. To pursue this goal, we have been always trying to provide all essential features of modern web frameworks - DOM templating, state, state binding, state derivation, effect, SPA, client-side routing and even hydration, in the simplest possible way. Simplicity is always among the top priorities of VanJS. The pursuit of simplicity helps VanJS maintain the title of world's smallest reactive UI framework.
Now, after evolving VanJS with 23 public releases, we feel that we can do even better. With
1.4.0release, we're simplifying VanJS's public API by reducing the top-level functions from 9 to 5!In this release, we took a deeper look at VanJS's entire API. We realized, some of functions are rarely being used. They can either be merged into other functions, completely replaced by other functions, or replaced by client-side solution in just several lines of code but with much greater flexibility. Thus, this release deprecates these functions. Since the overwhelming majority of applications don't use these functions at all, we expect most apps won't be affected. Even for the ones that do break, there will be an effortless migration pathway.
We believe less is more. Simplifying the API of VanJS will further flatten its learning curve, avoid the common confusion about less used functions, and ensures VanJS apps being built in a more consistent way.
✨ What's in the release?
1.
van.tagsandvan.tagsNSare merged into the same API.Prior to this release, people have to remember 2 different names for declaring tag functions -
van.tagsfor creating HTML elements, andvan.tagsNSfor creating elements with custom namespace URI (such as SVG or MathML elements). In VanJS1.4.0, with some adjustment of the implementation,van.tagsandvan.tagsNSare merged into the same name -van.tags. You can use:to declare tag functions for HTML elements, and use:
to declare tag functions for SVG elements.
2. Deprecate
van._asvan.derivecan be its drop-in replacementIn
1.4.0release, we deprecate functionvan._asvan.derivecan be its drop-in replacement wherevervan._is being used.van._was introduced in VanJS1.0.0to allow state-derivedon...event handlers (an escape mechanism to avoid binding functions being treated as event handlers). At that time, garbage collection for derived states wasn't implemented thus derived states need to be used very carefully to avoid memory leak. This situation was improved in1.1.0where garbage collection for derived states was implemented. After1.1.0release, derived states can be used freely just as other features in VanJS. Thus we can safety deprecatevan._by replacing all of its usage withvan.derive, see https://vanjs.org/tutorial#state-derived-event-handlers for reference.3. Deprecate
van.valandvan.oldValas they can be replaced by a few lines of code on the client sidevan.valandvan.oldValwere introduced in VanJS1.0.0as rarely used helper functions, primarily for component library authors, to deal with state and non-state input properties in a polymorphic way. i.e.:van.val(v)returns the value ofvregardless of whethervis aStateobject or not. However, we realized that this implementation is rather incomplete (e.g.: it doesn't evaluate the value ifvis a binding function), and users likely want to control over its resolution strategy (e.g.: whether to treat functions as binding functions or event handlers). Given it's rare forvan.valandval.oldValto support the real-world needs and it's easy to implement the solution on the user side, we decide to just deprecate these 2 functions. Users can usually replace them with a few lines of code on their side. For instance, the lines of code below implement a function that can resolve a static value, aStateobject and a binding function:You can refer to this section for more information.
4. Support
van.state()in TypeScript to create dummy or uninitializedStateobjectsThis release also adjusts
van.d.tsto allowvan.state()(callingvan.statewithout any argument) for creating a dummyStateobject (e.g.: for getting states' prototype object as shown in the code above) or creating aStateobject whose value will be initialized later.van.state()is already a valid usage prior to this release and in1.4.0we're making it pass the type checking.🛫 Migration guide
Most of the apps are expected to be unaffected by this release. But if your app uses one of the functions that are deprecated, you can follow the simple steps below to upgrade:
van.tagsNS, simply replacevan.tagsNSwithvan.tags.van._, simply replacevan._withvan.derive.van.valorvan.oldVal, you can replace it with a few lines of customized implementation illustrated in https://vanjs.org/tutorial#polymorphic-binding.The bundle size decreases thanks to the API simplification. Gzipped bundle decreases to
1012 bytes(1.9kB) from1049 bytes(37 bytesdecrease), while minified bundle decreases to1896 bytes(1.0kB) from1923 bytes(27 bytesdecrease) - maintaining to be the smallest reactive UI framework in the world.❤️ Hope you can enjoy!
Appendix
Why releasing the API simplification as
1.4.0instead of2.0.0?Technically, the API simplification brings some potential incompatibility and should be released as
2.0.0instead of1.4.0. However, after thinking through all the implications, I feel releasing it to1.4.0will bring us an easier way to proceed. If we release it as VanJS2.0.0, it will make the co-existence of 2 major VanJS versions: VanJS v1 and VanJS v2, which will bring significant amount of confusion and complexity.Specifically, when the users build an app on top of VanJS, they have to explicitly choose whether to use VanJS v1 or VanJS v2. To make things worse, since all the 3rd-party add-ons of VanJS at the moment are based on VanJS v1 (i.e.: having
^1.x.xin the dependency specifier), if a user decides to build an app based on VanJS v2 but also depends on one of the 3rd-party add-on, that will result 2 VanJS versions being imported to the app simultaneously, which will be sure to be problematic (Stateobjects and bindings in one version can't recognize the ones in the other version). A likely mitigation is to requires all VanJS-based libraries to support both versions and change the dependency specifier to something like>=1.x.x, but the requirement of being compatible with both VanJS versions will inevitably bring lots of complexity to the library implementation, which completely defeats the purpose of API simplification.On the flip side, since the functions that are deprecated in this release are truly the rarely used ones, we expect the number of apps that are broken by this release to be extremely small. And for the ones that do break, the migration will be simple and straightforward. Thus with the careful consideration of pros and cons of each choice, it's more beneficial to the VanJS ecosystem to release this version as
1.4.0instead of2.0.0.Beta Was this translation helpful? Give feedback.
All reactions