This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-08
Channels
- # admin-announcements (3)
- # arachne (1)
- # aws (2)
- # beginners (10)
- # boot (287)
- # cider (5)
- # clara (2)
- # cljs-dev (150)
- # cljsjs (2)
- # clojure (99)
- # clojure-austin (1)
- # clojure-brasil (1)
- # clojure-dev (13)
- # clojure-greece (55)
- # clojure-japan (1)
- # clojure-nl (2)
- # clojure-russia (24)
- # clojure-spec (184)
- # clojure-taiwan (1)
- # clojure-uk (45)
- # clojurescript (55)
- # clojurex (1)
- # cursive (20)
- # datascript (16)
- # datomic (1)
- # devcards (4)
- # events (10)
- # figwheel (1)
- # funcool (7)
- # hoplon (48)
- # immutant (1)
- # jobs (6)
- # lambdaisland (2)
- # lein-figwheel (19)
- # mount (36)
- # off-topic (37)
- # om (16)
- # om-next (17)
- # onyx (29)
- # planck (53)
- # proton (1)
- # pure-frame (1)
- # re-frame (40)
- # reagent (44)
- # remote-jobs (1)
- # ring (2)
- # robots (2)
- # rum (5)
- # slack-help (4)
- # spacemacs (27)
- # specter (82)
- # test-check (18)
- # test200 (1)
- # untangled (17)
@tolitius: ah, just got back to this. Does your solution only update the states when mount/stop and mount/start are called?
I'm using re-frame for my front end and I want to change some mutable fields on the webrtc javascript object when my app-db is updated
so setting fields on the mutable webrtc object isn't something that just happens on mount start, it happens throughout the lifecycle of the component.
@jiangts: if the map is {:socketURL (config :some-url) :onstream (config :on-stream-fn)}
, then after you change the config
and do
(mount/stop #'app/config)
(mount/start #'app/config)
the map will have updated values since it calls into config
to get them every time. unless I am missing something in your use case (I have not used reframe)right, I gathered the above code would update the fields. However, I thought it'd be cleaner if I didn't have to explicitly call mount/stop
and mount/start
every time I wanted to update the fields
for example, for the webrtc library i'm using, the user can toggle whether or not they want to stream audio, video, or both
I want the user to be able to click on buttons on the user interface to alter what the field contains to get the right behavior from webrtc
personally it feels a bit heavy handed to have to call mount/stop
and mount/start
each time a user clicks such a button
the reason i'm doing that is because adding a watch feels stateful to me, so i want that to be managed by mount
I see.. so the reason you want this map to be a mount's state is to add a lifecycle to this atom to add/remove watcher, right?
ok, and right now you do have it working by having a
(defstate my-map :start (create-atom-with-watcher) :stop (remove-watcher-and-reset-atom my-map)
?I guess it works at this point, I just hadn't figured it out when I first asked hte question 🙂 haha
I haven't used mount much, so the double deref @@
feels a bit ugly to me, but otherwise it works fine!
I saw the double deref in the datalog code example for cljs so I'm guessing it's acceptable enough
hold on, but
(defstate my-map :start (create-atom-with-watcher) :stop (remove-watcher-and-reset-atom my-map)
does not use @@
right, it is just an atom with a watcher?ah, not that code. I guess I never explicitly @@
, but it's just something I need to keep in mind. For example, now I need to make sure I swap!
on a @my-map
rather than just on my-map
thanks!! btw the clj(s) community is incredible, I almost never get to talk to library maintainers!!
but if you would have used mount for strictly clj
side of things, you would just do (swap! my-map fn)
there are a bit more details here: https://github.com/tolitius/mount/blob/master/doc/clojurescript.md#managing-state-in-clojurescript