[fix] destructuring in events for fx/defn macro

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-05-30 16:14:26 +02:00
parent 254639e586
commit f03225c03d
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
2 changed files with 10 additions and 3 deletions

View File

@ -2,12 +2,12 @@
(:refer-clojure :exclude [defn]))
(defn- register-events
[events interceptors name args]
[events interceptors name argsyms]
(mapv (fn [event]
`(status-im.utils.handlers/register-handler-fx
~event
~interceptors
(fn [cofx# [_# ~@args]] (~name cofx# ~@args))))
(fn [cofx# [_# ~@argsyms]] (~name cofx# ~@argsyms))))
events))
(defmacro defn
@ -55,5 +55,5 @@
(let [~cofx cofx#]
~@fdecl)
(throw (js/Error. (str "fx/defn expects a map of cofx as first argument got " cofx# " in function " ~name))))))
~@(register-events events interceptors (with-meta name m) args))
~@(register-events events interceptors (with-meta name m) argsyms))
(throw (Exception. (str "fx/defn expects a vector of keyword as value for :events key in attr-map in function " name))))))

View File

@ -29,6 +29,13 @@
[{:keys [db]} b]
(identity nil))
(fx/defn hello6
"lol lazy function does nothing"
{:events [:test2]}
[{:keys [db]} {:keys [a b]}]
{:db {:a (identity a)
:b b}})
(deftest merge-fxs-test
(testing "merge function for fxs"
(let [cofx {:db {:c 2}}]