Skip to content

Commit

Permalink
e/partial - port from v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dustingetz committed Aug 8, 2024
1 parent 8331128 commit dee4f6a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/hyperfiddle/electric_de.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ A mount point can be :

(defmacro apply [& args] `($ Apply ~@args))

(defmacro partial
"Like `cc/partial` for reactive functions. Requires the target function
arity (`argc`) until reactive function supports variadic arguments.
e.g. (new (partial 2 (e/fn [a b] [a b]) :a) :b) ;; => [:a :b]"
[argc F & args]
(if (= 0 argc)
F
(let [rest-args (map #(symbol (str "arg_" %)) (range (- argc (count args))))]
`(let [F# ~F]
(hyperfiddle.electric-de/fn ~@(when (symbol? F) [F]) [~@rest-args]
($ F# ~@args ~@rest-args))))))

(cc/defn on-unmount* [f] (m/observe (cc/fn [!] (! nil) f)))

(defmacro on-unmount "Run clojure(script) thunk `f` during unmount.
Expand Down

0 comments on commit dee4f6a

Please sign in to comment.