This is part one of a two part series on Stimulus controller communication. The link to part two will be located here once it has been published.
From the time I’ve started playing around with Stimulus, I’ve been thinking about the best way that controllers can communicate with each other.
The nice thing about Stimulus is that the state of the controller is representable from within the DOM itself,
meaning that if a property
of a controller needs to change, it can be done so by simply modifying the attribute value of the element the controller is bound to
(see here for how that works).
This, however, doesn’t extend nicely to instances when you only need to notify the controller of an event or send a
message that is more one shot: “I did a thing”, or “please do that thing”. It’s not always possible to translate these interactions to
one that is based on modifying attribute values, and most attempts to do so always end up as a bit of a code smell.
After a bit of experimentation, I think I’ve found a method which works for me.
Read more →
Over the last several months, I’ve been doing a bit of development
using Buffalo, which is a rapid web development framework in Go,
similar to Ruby on Rails. Like Ruby on Rails, the
front-end layer is very simple: server-side rendered HTML with a bit of jQuery augmenting
the otherwise static web-pages.
After a bit of time, I wanted to add a bit of dynamic flare to the frontend, like automatically
fetch and update elements on the page. These projects were more or less small
personal things that I didn’t want to spend a lot of time maintaining, so
doing something dramatic like rewriting the UI in React or Vue would have been overkill.
jQuery was available to me but using it always required a bit of boilerplate to setup the bindings
I since came across Stimulus, which looks to provide what I was looking for.
Read more →