CLJC: fix subs handlers to supply correct arity

This commit is contained in:
Sam Roberton 2016-07-21 17:56:46 +10:00
parent ef3656ff60
commit 02ec0c26e6

View File

@ -154,22 +154,37 @@
sub-fn ;; first case the user provides a custom sub-fn sub-fn ;; first case the user provides a custom sub-fn
(register (register
sub-name sub-name
(fn [db q-vec d-vec] (fn subs-handler-fn ;; multi-arity to match the arities `subscribe` might invoke.
(let [subscriptions (sub-fn q-vec d-vec)] ;; this let needs to be outside the fn ([db q-vec]
(make-reaction (let [subscriptions (sub-fn q-vec)]
(fn [] (f (multi-deref subscriptions) q-vec d-vec)))))) (make-reaction
(fn [] (f (multi-deref subscriptions) q-vec)))))
([db q-vec d-vec]
(let [subscriptions (sub-fn q-vec d-vec)]
(make-reaction
(fn [] (f (multi-deref subscriptions) q-vec d-vec)))))))
(seq arrow-args) ;; the user uses the :<- sugar (seq arrow-args) ;; the user uses the :<- sugar
(register (register
sub-name sub-name
(fn [db q-vec d-vec] (letfn [(get-subscriptions []
(let [subscriptions (map subscribe arrow-subs) (let [subscriptions (map subscribe arrow-subs)]
subscriptions (if (< 1 (count subscriptions)) (if (< 1 (count subscriptions))
subscriptions subscriptions
(first subscriptions))] ;; automatically provide a singlton (first subscriptions))))] ;; automatically provide a singleton
(make-reaction (fn subs-handler-fn
(fn [] (f (multi-deref subscriptions) q-vec d-vec)))))) ([db q-vec]
(let [subscriptions (get-subscriptions)]
(make-reaction
(fn [] (f (multi-deref subscriptions) q-vec)))))
([db q-vec d-vec]
(let [subscriptions (get-subscriptions)]
(make-reaction
(fn [] (f (multi-deref subscriptions) q-vec d-vec))))))))
:else :else
(register ;; the simple case with no subs (register ;; the simple case with no subs
sub-name sub-name
(fn [db q-vec d-vec] (fn subs-handler-fn
(make-reaction (fn [] (f @db q-vec d-vec)))))))()) ([db q-vec]
(make-reaction (fn [] (f @db q-vec))))
([db q-vec d-vec]
(make-reaction (fn [] (f @db q-vec d-vec))))))))())