This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-25
Channels
- # admin-announcements (2)
- # beginners (36)
- # boot (37)
- # cider (65)
- # cljsrn (92)
- # clojars (3)
- # clojure (225)
- # clojure-austin (5)
- # clojure-belgium (2)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-greece (2)
- # clojure-mexico (3)
- # clojure-news (2)
- # clojure-quebec (1)
- # clojure-russia (14)
- # clojure-spec (24)
- # clojure-uk (53)
- # clojurescript (34)
- # cursive (14)
- # datascript (9)
- # datomic (4)
- # defnpodcast (8)
- # devcards (30)
- # dirac (7)
- # editors (7)
- # emacs (1)
- # figwheel (1)
- # hoplon (85)
- # immutant (2)
- # incanter (1)
- # luminus (5)
- # off-topic (41)
- # om (18)
- # onyx (11)
- # perun (2)
- # re-frame (11)
- # reagent (9)
- # ring (3)
- # spacemacs (2)
- # spirituality-ethics (1)
- # test-check (19)
- # testing (12)
- # untangled (14)
- # yada (9)
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).
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 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