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.
-
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.0
release, 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.tags
andvan.tagsNS
are merged into the same API.Prior to this release, people have to remember 2 different names for declaring tag functions -
van.tags
for creating HTML elements, andvan.tagsNS
for creating elements with custom namespace URI (such as SVG or MathML elements). In VanJS1.4.0
, with some adjustment of the implementation,van.tags
andvan.tagsNS
are 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.derive
can be its drop-in replacementIn
1.4.0
release, we deprecate functionvan._
asvan.derive
can be its drop-in replacement wherevervan._
is being used.van._
was introduced in VanJS1.0.0
to 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.0
where garbage collection for derived states was implemented. After1.1.0
release, 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.val
andvan.oldVal
as they can be replaced by a few lines of code on the client sidevan.val
andvan.oldVal
were introduced in VanJS1.0.0
as 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 ofv
regardless of whetherv
is aState
object or not. However, we realized that this implementation is rather incomplete (e.g.: it doesn't evaluate the value ifv
is 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.val
andval.oldVal
to 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, aState
object and a binding function:You can refer to this section for more information.
4. Support
van.state()
in TypeScript to create dummy or uninitializedState
objectsThis release also adjusts
van.d.ts
to allowvan.state()
(callingvan.state
without any argument) for creating a dummyState
object (e.g.: for getting states' prototype object as shown in the code above) or creating aState
object whose value will be initialized later.van.state()
is already a valid usage prior to this release and in1.4.0
we'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.tagsNS
withvan.tags
.van._
, simply replacevan._
withvan.derive
.van.val
orvan.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 bytes
decrease), while minified bundle decreases to1896 bytes
(1.0kB) from1923 bytes
(27 bytes
decrease) - maintaining to be the smallest reactive UI framework in the world.❤️ Hope you can enjoy!
Appendix
Why releasing the API simplification as
1.4.0
instead of2.0.0
?Technically, the API simplification brings some potential incompatibility and should be released as
2.0.0
instead of1.4.0
. However, after thinking through all the implications, I feel releasing it to1.4.0
will 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.x
in 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 (State
objects 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.0
instead of2.0.0
.Beta Was this translation helpful? Give feedback.
All reactions