Introducing VanX: The official VanJS extension that enables more ergonomic code #144
Replies: 4 comments 14 replies
-
Digging this a lot! Just in time as I get back to some frontending after weeks of backending. Being more of a fair-weather [Ecma|Type]scripter, I find this challenging to grok:
I understand the "standard" filter semantics as returning a bool depending on the input, |
Beta Was this translation helpful? Give feedback.
-
Btw might inclusion of X in https://vanjs.org/start#download-table be feasible? Being decidedly JS-deps-free apart from VanJS, I rather like manual (non-node_modules or similar) "package" "management" ... 😁 |
Beta Was this translation helpful? Give feedback.
-
Hi, to use vanX do I also need to import vanJS? <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-1.2.7.nomodule.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vanjs-ext@0.2.0/dist/van-x.nomodule.min.js"></script> or only the van-x script? |
Beta Was this translation helpful? Give feedback.
-
@Tao-VanJS would it be right to call this a store library? |
Beta Was this translation helpful? Give feedback.
-
📣 VanX
0.4.0
brings lots of new features: Smart diff, global app state, server-driven UI, serialization and more →Hi fellow VanJSers,
I'm thrilled to announce: VanX, the official VanJS extension is finally here! 🎉🎉🎉
VanX is a collection of utility functions that enable you to write more ergonomic code for your apps. In this release, it provides 2 primary functionalities:
vanX.reactive
: Grouping many VanJS states into a single reactive objectvanX.reactive
helps you define a single reactive object that is ideal for holding manyState
objects for the status of your application. The fields of the reactive objects can be deeply nested. Let's take a look at an example below:Getting and setting the fields in the reactive object is equivalent to getting and setting the values of its underlying states. With the reactive object, it's easy to define DOM nodes on top of its fields:
Note that, not only you can set the value of each individual leaf field, you can also set the entire object of a subfield. For instance, the following code:
is equivalent to:
All the bound UI elements are guaranteed to be updated accordingly, no matter which way you set the fields.
You can also specify calculated fields in the reactive object, the value of a calculated field depends on the values of other fields according to a calculation function. For instance, we can have a reactive object with calculated fields like that:
Calculated fields can be used the same way as other fields.
Preview a sample app via CodeSandbox
You can refer to https://vanjs.org/x#reactive-object for more information about
vanX.reactive
.vanX.list
: Building a reactive list that minimizes DOM re-rendering when its values are updatedvanX.list
is a utility function that helps you build a UI element based on a reactive list of values. It supports both non-keyed data (if the reactive object is an array) or keyed data (if the reactive object is a plain object).Any change to the reactive list, such as inserting an item, updating an item, or deleting an item will be propagated to the UI elements it's bound to.
With the help of
vanX.list
, we can re-implement the reactive TODO app with substantial simplification (40+ lines of code => just over 10 lines):Try on jsfiddle
You might notice how easy it is to serialize/deserialize a complex reactive object into/from external storage. This is indeed one notable benefit of reactive objects provided by
vanX.reactive
.Not only you can update the list object one item at a time, we also provide the
vanX.replace
function that enables you to update, insert, delete and reorder items in batch. Let's take a look at the examples below:Preview sample apps where
vanX.list
andvanX.replace
are being used: App 1, App 2.You can refer to https://vanjs.org/x#reactive-list for more information about
vanX.list
.Since the public release of VanJS, we have received enormous feedback from the community. There are common pain points expressed by its users as well as scenarios where programming with VanJS feels different compared to other UI frameworks. VanX is the effort to bridge the gap and address the most prominent pain points of VanJS. I am hoping it can bring the developer experience of VanJS into the next level!
❤️ Hope you can enjoy!
Beta Was this translation helpful? Give feedback.
All reactions