Skip to content

Commit

Permalink
Remove extra level of inderction when creating dynamic subscription
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielcompton committed Aug 28, 2015
1 parent 8b796c3 commit 9193124
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/re_frame/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))

0 comments on commit 9193124

Please sign in to comment.