The Clojure docs for atoms reference concepts like threads, atomic changes, and spin loops. Since those don’t apply to a single-threaded environment, why would you ever use an atom?

Atoms provide a way to manage shared, synchronous, independent state.

In a single-threaded environment like the browser, it’s idiomatic to store all application state in an atom. All updates to the application state are done via swap! and reset!. Then, your functions for generating the DOM can deref the atom to get the relevant state.

Get access to new content

New posts are at bostonou.com. Go check it out, or you can just subscribe from here.

    Reminder: You're subscribing to bostonou.com