Allow lit-html-like templates as worthy, yet build-free JSX replacement #10
Replies: 3 comments 10 replies
-
Hy Cloudspeech, I personnaly love the tiny size of VanJS and would'nt want to see it growing... Is this code really hard to read for React users ? : import v from "./van.js"
const {span, h1, div, img } = v.tags
const add = (base) => (elt) => v.add(base, elt)
const target = document.getElementById("app")
const title = document.getElementById("title")
const style_user_pict = `
border:1px solid orange;
padding: 3px;
margin:10px`;
function User (user) {
return (
// User wrapper
div ({style:"display:flex; align-items:center;width:90%;"},
// User picture
div({style:"margin-right:10px"},
img({style:style_user_pict, src:user.picture.thumbnail})
),
// User name
div (
span(user.name.first, " "),
span(user.name.last)
)
)
)
}
function toJson(r) {
return r.json()
}
function displayUsers (users) {
add(title)(div("Random Users API"))
users.results.map(user => add(target)(
User(user))
)
}
fetch("https://randomuser.me/api?results=5")
.then(toJson)
.then(displayUsers) And this one ? Demo import van from "./van.js"
const {button,span, div, pre, h1} = van.tags
const elapsed = van.state("0.00")
const Stopwatch = () => {
let id;
const start = () => id = id || setInterval(() =>
elapsed.val = (Number(elapsed.val) + 0.01).toFixed(2), 10)
return span(
button({onclick: start}, "Start"),
button({onclick: () => (clearInterval(id), id = 0)}, "Stop"),
button({onclick: () =>
(clearInterval(id), id = 0, elapsed.val = "0.00")}, "Reset"),
)
}
const Screendisplay = () => h1(elapsed, " s")
van.add(app, div(
h1("A Simple Stopwatch"),
div ({class:"stopwatch"},
div({class:"content"},
Screendisplay(),
Stopwatch())
)
)
) VanJS is very orignal like it is. The risk of creating addons is to lost new users, and finish like the Jquery Plugins, with all Let us keep VanJS thin (and even thiner if possioble :-)) and performant Look at HyperApp, it started thin, and now :.... No offense Regards |
Beta Was this translation helpful? Give feedback.
-
Very bad suggestion. Almost all other JS frameworks use JSX and it's ugly, too verbose, too much noise vs data. |
Beta Was this translation helpful? Give feedback.
-
@Tao-VanJS Hi, Can you check our repo a jsx-runtime powerd by VanJS. I think this implementation nicely solves the problem under discussion |
Beta Was this translation helpful? Give feedback.
-
VanJS' HTML-markup-as-nested-JS-function-calls approach to templating is going to be a hard sell to the wider community, especially people that have seen React. They just want something like JSX.
Lit-html has a very nice syntax that comes very close to JSX, yet only uses browser-native means. See https://lit.dev/docs/templates/overview/.
I humbly suggest to not reinvent the wheel but provide an add-on to VanJS that supports unchanged lit-html template syntax (properties, attributes, events at minimum, perhaps also ref). This way the vanJS base size can be kept minimal for purists.
I expect the add-on's size to likewise be very small (using DOMParser).
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions