Fork me on GitHub

Does anyone know how things outside DOM should be controlled in this case?

;; db.cljs
(def default-db {:document-title "My SPA"})

;; subs.cljs
(register-sub :document-title 
  (fn [db] (reaction (:document-title @db))))

;; views.cljs
(defn main-panel []
  (let [document-title (subscribe [:document-title])]
    ;; (do @document-title nil) Sorry, this is wrong. ↓ is right.
    (do (set! (. js/document -title)  @document-title) nil)

;; document.title == 'My SPA'
In this case, I want to change the value of document.title via app-db changes. I accomplished it with the above code, but I believe there's a more intuitive/easy way. Give me some hints.


@knjname: event handlers change "the state of the world", including app-db.


(so too does middleware on event handlers)


So, whatever cause the change in app-db, would normally ALSO be responsible to changing document.title as well .


If there are multiple handlers which might make that change, then you might want to use on-change middleware to "watch for changes", maybe.


@mikethompson: Thank you for your nice hints. I get it partially. In the above my post, I had thought the same rule is applied to non-DOMs like DOM getting the changes in the flow i.e. event-handler => app-db => subscription => DOM. All app's state should exist in sole app-db and all changes to DOMs/non-DOMs should derive from it. Does your idea suggest that there can be multiple state such as document.title?


Yeah, the reactive part only exists between app-db and the DOM. Rich Hickey said that clojurescript is 80% fuctional. Along the same lines, I'd say that re-frame is 50% reactive 🙂 You are talking about a mutative operation - and that's something that belongs in an event handler. They are the part of the framework which mutates (although the soon via Effects handlers).


Thank you! I'm looking forward to Effects handlers.


anyone had success working in devcards with re-frame?


wondering what strategies people have employed to use the app-db etc while still keeping components isolated


Reposted from Clojurescript channel for completeness Best I've seen so far can be found at with a brief discussion about it near the bmottom of I'm hoping to put some time in this week to get something written up in the re-frame and devcards wikis if I can get something working with it