jorgebucaran / superfine

Absolutely minimal view layer for building web interfaces
https://git.io/super
MIT License
1.57k stars 78 forks source link

Minimum example of a table with some sorting #181

Closed mike-ward closed 4 years ago

mike-ward commented 4 years ago

Fooling around and wrote this quick table sample. Click on the Author to sort.

https://is.gd/sb3Bqt

jorgebucaran commented 4 years ago

Excellently done! Thank you for sharing, @mike-ward. đź‘‹

Here's my revision.

mike-ward commented 4 years ago

Another variation

Couple of questions:

 const setState = (state) =>
    patch(
      document.getElementById("app"),
      h("main", {}, [
        h('h1', {}, text("Cat Facts")),
        factsTable(state)
      ])
    )

Really like the simplicity and just noodling around to understand it better.

jorgebucaran commented 4 years ago

1) The id is unknown to Superfine (since it's not declared in your view/VDOM) and Superfine won't touch any attributes it doesn't know about—how well-mannered! It gets there because Superfine recycles the existing main element instead of throwing it away and creating it from scratch. 2) Hmm, I don't think so. While some VDOMs might behave like that, Superfine works by replacing or patching the DOM root/element (in this case patching because your HTML element matches the root element in your VDOM). 3) Gotcha. I think I covered this above.

Let me know if this covers everything for you. 🙏

Really like the simplicity and just noodling around to understand it better.

That's awesome. Thank you!

mike-ward commented 4 years ago

An overload to the h() API that takes its children as splat arguments would be helpful.

h(type, props, ...children)

Mithril JS does this and I've found it useful.

jorgebucaran commented 4 years ago

I believe that's easy enough to implement in userland and import into your project. I also have a dislike for variadic functions.