In an effort to learn ClojureScript, I’m wanting to do quick/simple examples I’ve either done before or that are used by other languages. The first one I’m trying is one of Elm’s example of a simple counter.
I’m using only
shadow-cljs and hiccups. I’d like to do this as minimally as possible for learning purposes. Using Reagent would obviously make this trivial, but I’d rather not.
Here’s what I have so far:
(ns counter.core (:require-macros [hiccups.core :as hiccups :refer [html]]) (:require [hiccups.runtime :as hiccupsrt])) (def init-model (atom 0)) (defn view [model] (html [:div [:div (str "Count: " model)] [:button "+"] [:button "-"]])) (defn update-model [msg model] (case msg "plus" (swap! model inc) "minus" (swap! model dec) model)) (defn ^:export main  (set! (.-innerHTML (js/document.getElementById "app")) (view (update-model "plus" @init-model))))
To test what I have thus far, I wanted to hardcode arguments when I call the
view function there at the bottom. I’m getting the following error when I do:
Error: No protocol method ISwap.-swap! defined for type number: 0
I’m not really sure what to do with this. I couldn’t find much help elsewhere online when searching for this error message. Thanks for any help you could possibly offer me.