VanJS: Getting Started
To get started, add the line below to your script:
import van from "https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-0.12.4.min.js"
To code without ES6 modules, add the following line to your HTML file instead:
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/vanjs-org/van/public/van-0.12.4.nomodule.min.js"></script>
Alternative, you can download the files (van-0.12.4.min.js
, van-0.12.4.nomodule.min.js
) and serve them locally.
Test It Out
The following code will produce a funnier Hello
component:
const {button, div, pre} = van.tags
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const Run = ({sleepMs}) => {
const headingSpaces = van.state(40), trailingUnderscores = van.state(0)
const animate = async () => {
while (headingSpaces.val > 0) {
await sleep(sleepMs)
--headingSpaces.val, ++trailingUnderscores.val
}
}
animate()
const helloText = van.bind(headingSpaces, trailingUnderscores,
(h, t) => `${" ".repeat(h)}ππ¨Hello VanJS!${"_".repeat(t)}`)
return div(pre(helloText))
}
const Hello = () => {
const dom = div()
return div(
dom,
button({onclick: () => van.add(dom, Run({sleepMs: 2000}))}, "Hello π"),
button({onclick: () => van.add(dom, Run({sleepMs: 500}))}, "Hello π’"),
button({onclick: () => van.add(dom, Run({sleepMs: 100}))}, "Hello πΆββοΈ"),
button({onclick: () => van.add(dom, Run({sleepMs: 10}))}, "Hello ποΈ"),
button({onclick: () => van.add(dom, Run({sleepMs: 2}))}, "Hello π"),
)
}
van.add(document.body, Hello())
Demo:
Download Table
The current version of VanJS is 0.12.4
(announcement). You can find all relevant VanJS files to download in the table below:
Click the link to download the file, or π to copy the import line from CDN.
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.12.4.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.12.4.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.4.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.4.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
Historical Versions
0.12.3
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.12.3.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.12.3.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.3.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.3.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.12.2
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.12.2.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.12.2.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.2.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.2.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.12.1
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.12.1.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.12.1.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.1.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.1.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.12.0
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.12.0.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.12.0.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.0.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.12.0.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.11.11
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.11.11.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.11.11.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.11.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.11.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.11.10
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.11.10.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.11.10.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.10.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.10.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
0.11.9 (First Public Release)
This is the first public release of VanJS. See the announcement.
Files | Description |
---|---|
| Minified script file for ES6 modules, optimized for bundle size. |
| The source file without minification. |
| The script file for debugging purpose, compared to van-0.11.9.js , it adds additional sanity checks, such as type-checking, including the checkings that are impossible to do with TypeScript. Using this file for development purpose will detect issues earlier and produce more meaningful error messages. |
| Similar to van-0.11.9.min.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.9.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |
| Similar to van-0.11.9.debug.js , but designed to work in non-module context, such as inline JavaScript or <script type="text/javascript"> . |