This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-19
Channels
- # adventofcode (4)
- # beginners (80)
- # boot (4)
- # cbus (2)
- # cider (62)
- # clara (18)
- # cljs-dev (8)
- # cljsrn (10)
- # clojure (139)
- # clojure-brasil (3)
- # clojure-dev (27)
- # clojure-italy (1)
- # clojure-russia (3)
- # clojure-spec (4)
- # clojure-uk (47)
- # clojurescript (102)
- # core-async (10)
- # cursive (7)
- # datomic (71)
- # emacs (32)
- # fulcro (99)
- # funcool (1)
- # hoplon (3)
- # jobs (1)
- # jobs-discuss (6)
- # jobs_rus (2)
- # leiningen (3)
- # luminus (2)
- # lumo (14)
- # mount (7)
- # off-topic (19)
- # re-frame (25)
- # ring-swagger (4)
- # rum (3)
- # shadow-cljs (142)
- # specter (2)
- # sql (16)
- # timbre (1)
- # vim (3)
Any way to input the db as input signal to a sub with out creating a db sub?
At my router, this works:
(re-frame/reg-sub
::active-panel
(fn [db _]
(:active-panel db)))
(defn main-panel []
(let [active-panel (re-frame/subscribe [::active-panel])]
[pages/panels @active-panel]))
but this doesn't:
(def state->pouch_sub (keyword (str pouchDatabaseName "-sub")))
(re-frame/reg-sub
state->pouch_sub
(fn [db [_ _]]
(:charlie db)))
(let [freshStateData (re-frame/subscribe [state->pouch_sub])]
(.log js/console @freshStateData "subscription")))
It seems pretty much the same. Same trivial subscription syntax, same let
, same @
for dereferencing. But the first piece of code updates the active page live just like it have to be, while second doesn't work at all, it's being executed just when i hit Ctrl + S
and figwheel reloads pageI've tried to change generated keyword to something static like :hello
, but it doesn't work anyways
I tried reg-sub-raw
:
(re-frame/reg-sub-raw
state->pouch_sub
(fn [app-db _]
(reaction (get-in @app-db [(keyword pouchDatabaseName)]))))
But it works just like reg-sub
: one time one page reload, it doesn't work live@melvoloskov you need something for React in order for reaction
to work which is the basic building block behind reagent atom
and re-frame subscriptions
All the magic gets binded to React under the hood which does it's magic via virtual DOM, if you do not add anything to the DOM it can't do it's magic
Usually in browser stuff gets initiated by three ways: user interaction (you have DOM), server side data (you save data to db, UI components react to this) or via scheduled operation
Basically, if you want to do something else than show stuff in UI on db change then use effects
@melvoloskov > But how do I execute arbitrary function on db changes? You generally don't need to. If you do: - you can use Track in the library given above. - you can use an effect handler to also do dirty work.
yeah, sorry, i did
@melvoloskov You do have another option which is to utilize the add-watch
function in clojure.core. Since re-frame's app-db is an atom you can register your own functions to watch it and execute function when it changes. I probably wouldn't use that method for anything other than logging or debugging though.