Iteration #4: Dumdom’s top-level event handler
When we finally reached the end, this is what we had left:
(d/render
[:form
[:input {:value "christian@kodemaker.no"}]
[:button
{:onClick [[:save-in-store :email-status :saving]
[:ui-event :saved-email]
[:save-email "christian@kodemaker.no"]]}
"Lagre e-postadressen"]]
(js/document.getElementById "app")
{:handle-event (fn [e data]
(println "Event triggered")
(println data)
(println (.-target e)))})
The original idea of giving Dumdom a message bus has been scrapped in favor of
Dumdom supporting a global event handler which is called if you specify
something other than a function on attributes like :onClick
. But the dream of
an integrated message bus in the rendering library is not dead: Dumdom now
provides just enough tools for us to hook into the message bus we already have
in our app.
Note that Dumdom no longer needs to know anything about your event data. It just
forwards it to the handler, and it’s up to you to do something sensible with it.
Want to forward the data to a message bus? Go ahead! Want to interpolate values
from the event? Fine, create an interpolation function and plug it in.
Achieve more by doing less
The resulting
commit
was small and neat, and roughly ~10 lines of code were added to Dumdom for this
feature, ignoring docs, tests, etc.
Why ship something so stripped down? With this change, Dumdom has created
opportunities for its users without succumbing to scope creep. It remains a
small, lightweight rendering library, and if you take advantage of this new
feature, Dumdom does its job even better.
“Look at all the things I’m not doing,” was once said in a legendary screencast.
Back then it was about implicit assumptions, here it’s about doing no more than
exactly enough. If I still want to deliver a “batteries included” solution for
messaging in Dumdom, I can build that in a separate library. By composing these
from the outside, we ensure Dumdom a stable future. All the assumptions, code,
and documentation discarded along the way are code that won’t gather new bugs or
security holes, won’t confuse users, and won’t open the door to accumulating
even more nearly-related features.
This way, Dumdom can become “finished”. Finished code is code you don’t have to
waste time updating, maintaining, and chasing after. That frees your time for
something more valuable. You simply achieve more by having your things do less.
A big thanks to Magnar and Anders, who deserve much of
the credit for Dumdom getting such a nice extension as it did.