Svelte's main different to React is that it doesn't use a VDOM. it "knows" what to update from construction time.
I was wondering if I could build anything that gave the same benefits, no vdom dependency, without needing a special compiler. .svelte files need to be processed before they can be run in the browser.
I've got to something that looks like this. https://github.com/CrowdHailer/eyg-lang/blob/61746198448c86d0abb691acfa95710483222d75/eyg/src/experiment.gleam#L107-L117
p(
[
class(if_(loud, value("bold underline text-red-500"), value(""))),
attr(value("foo"), greeting),
],
[
text(value("hello ")),
text(greeting),
if_(loud, p([], [text(greeting)]), text(value(""))),
],
)
p and text are defined in the framework. Currently only text supports memoisation but it only touches the dom if the update value is new.
https://github.com/CrowdHailer/eyg-lang/blob/61746198448c86d0abb691acfa95710483222d75/eyg/src/experiment.gleam#L56
currently this uses a mutable ref, maybe there is a way to manage without this
value is a shorthand function to to create values that are constant.
The uglies bit is greeting and loud which need to be defined for the specific state of the application. https://github.com/CrowdHailer/eyg-lang/blob/61746198448c86d0abb691acfa95710483222d75/eyg/src/experiment.gleam#L90-L102
Maybe there is a way to generate these in the future. Not sure.
Anyway looking for thoughts comments. is this useful? Is it nice that it's gleam only, i.e. not bindings to Svelte? who else has already built this?