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.

Grow As A Professional Developer

I write about ClojureScript and what it means to be a professional.
Sign up to get posts directly in your inbox.

    I won't send you spam. Unsubscribe at any time.