Remove extra level of indirection when creating dynamic subscription

Instead of creating a RAtom and resetting into it on a seperate side
chain of our dependency graph, we can instead return a reaction which is
the result of @@sub, achieving the same goals but with less code and
complexity.
This commit is contained in:
Daniel Compton 2015-08-28 14:38:57 +12:00
parent 12b71b85e5
commit 518ff995dc
1 changed files with 5 additions and 7 deletions

View File

@ -36,10 +36,8 @@
handler-fn (get @key->fn key-v)]
(if (nil? handler-fn)
(error "re-frame: no subscription handler registered for: \"" key-v "\". Returning a nil subscription.")
(let [result (reagent.ratom/atom nil)
dyn-vals (reaction (mapv deref dynv))
sub (reaction (handler-fn app-db v @dyn-vals))
;; handler-fn returns a reaction which is then wrapped in the sub reaction
;; need to double deref it to get to the actual value.
_ (run! (reset! result @@sub))] ;; run! here to force this to be started, won't ever run otherwise
result)))))
(let [dyn-vals (reaction (mapv deref dynv))
sub (reaction (handler-fn app-db v @dyn-vals))]
;; handler-fn returns a reaction which is then wrapped in the sub reaction
;; need to double deref it to get to the actual value.
(reaction @@sub))))))