Fork me on GitHub
#re-frame
<
2016-07-25
>
knjname06:07:04

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.

mikethompson07:07:13

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

mikethompson07:07:38

(so too does middleware on event handlers)

mikethompson07:07:13

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

mikethompson07:07:17

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

knjname08:07:32

@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?

mikethompson08:07:37

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).

knjname09:07:58

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

mattsfrey16:07:55

anyone had success working in devcards with re-frame?

mattsfrey16:07:06

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

shaun-mahood17:07:23

Reposted from Clojurescript channel for completeness Best I've seen so far can be found at https://github.com/nberger/devcards/blob/iframe/example_src/devdemos/re_frame.cljs with a brief discussion about it near the bmottom of https://clojurians-log.clojureverse.org/re-frame/2016-07-15.html 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