Weekly Brain Dump #44
At a Glance
- Unhinged Class Components Class based components!
- The Write Clean Opal migration
- Interesting Links Cool things I found this week
- Comments
Unhinged Class Components
I started implementing Unhinged into The Write Clean and immediately got annoyed with it and it’s limitations. This spurred me on to work getting class components working instead of having to use the awkward DSL I made.
So the old DSL component looked like this:
Mithril::Component.define(:Counter) do
oninit do
state[:count] = 0
end
view do
div {
plain "Current count: #{state[:count]}"
a(
class: "card-footer-item",
onclick: ->(e) {
e.JS.preventDefault
state[:count] -= 1
},
href: "#"
) { plain "-" }
a(
class: "card-footer-item",
onclick: ->(e) {
e.JS.preventDefault
state[:count] += 1
},
href: "#"
) { plain "+" }
}
end
end
And the new class components look like this:
class Counter
include Unhinged::Component
def initialize
@count = 0
end
def view
div {
plain "Current count: #{@count}"
a(
onclick: ->(e) {
e.JS.preventDefault
@count -= 1
},
href: "#"
) { plain "-" }
a(
onclick: ->(e) {
e.JS.preventDefault
@count += 1
},
href: "#"
) { plain "+" }
end
end
end
While it may not look like much of a difference you really feel it when working with the components. This feels so much more like you’re writing standard ruby.
This also involved rewriting HtmlRenderer from being initialised
recursively as instances of a Class to being a Module that uses a stack
based way of building up the DOM. It was really refreshing to do such a
difficult coding task by hand after having to use AI so much at work.
The Write Clean
I have switched all the JavaScript to use Opal instead now. I started looking into using Unhinged but as I said above, I hit issues and decided to tackle fixing that project first.
I’m hoping to make more progress on The Write Clean this week now that I’ve fixed up Unhinged.
I’m very thankful that the database structure I setup will actually be nearly perfect for the new features we have planned, so that’s left me feeling pretty good about my past decisions.
Interesting Links
Running Code in the Crystal Type System: Articles like this make me realise just how crazy powerful type systems are.
Unrolled Code: Some absolutely amazing usage of meta-programming in Ruby.
Hopwell: A really fun Tetris-like about ascending a frog.
I paid people to try and follow my README: This is something I think would be great to do with Taylor.