Elm is usually pretty clear, but there are certain things that are a little hard to search for.
One of those is the
! operator, introduced in 0.17.
What does it do?
Where does it come from?
And even more important, when should you use it?
When you’re building an app with Elm, you’ll find a common problem: where do you
put shared state in models? Let’s take selecting an item for viewing as an
example. You’ll start out having a model field with a selected item and one with
a collection. But that’s duplication! How do you keep the model state in sync
when one side has to change?
Imagine: you’re implementing your Elm app. It’s getting bigger all the time, and
you’re happy that it’s growing. Hooray! But now you need to make HTTP
requests… from a child component. What to do? You don’t want to duplicate
the HTTP config as a field on the user everywhere, right? But likewise, you
don’t want to forward actions to the parent just to make HTTP requests, right?
What’s the way to solve this while sticking with the best architecture for your
In our previous article we talked about
how parents and children can communicate with one another in Elm. But how about
when you need two child components to know about each others state? Hmm…
Nobody wants to feel like their application holds together by duct tape and
baling wire. Coupling components is icky, but… sometimes you’ve got a
parent and child components that just have to talk to each other. It can feel
like you’re missing something simple when these situations come up. Do you have
to give up on clean separation of concerns just to get it working? There’s hope,
though: this problem is not as difficult as it seems on the surface.