DEV Community

artydev
artydev

Posted on

2

It's time to switch from MithrilJS to VanJS

I have been and always be a big fan of MithrilJS (see my previous posts).

But VanJS changed it all by it's simple API and very tiny size (1.2K)
There is no more reason to use Mithril, at least for me...

Here is a simple Counter in Mithril and VanJS, compare and choose your weapon :-)

Demo

import van from "./van.js"
const {button, h1, span, div} = van.tags

// MITHRIL
var count = 0 // added a variable
var Hello = {
    view: function() {
        return m("main", [
            m("h1", {class: "title"}, "Mithril Counter"),
            // changed the next line
            m("button", {onclick: () => ++count}, count + " clicks"),
        ])
    }
}

m.mount(root, Hello)

//VanJS
// Create a new State object with init value 1
const counter = van.state(1)

let Counter = div (
  h1("VanJS Counter ", counter),
  button({onclick: () => counter.val++}, span(counter, " clicks"))
)

van.add(document.body, Counter)

Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay