Skip to content

Commit

Permalink
Allow multivalued handlers to mix js and callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatu Tarvainen committed Jan 12, 2021
1 parent d05b3da commit c78e35b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ripley/html.clj
Expand Up @@ -62,6 +62,11 @@

(defn register-callback [callback]
(cond
;; Multiple values, join by semicolon
(vector? callback)
(str/join ";" (map register-callback callback))

;; A callback record
(instance? ripley.js.JSCallback callback)
(let [invoke-callback-js (str "ripley.send("
(p/register-callback! context/*live-context*
Expand All @@ -72,9 +77,11 @@
(str "if(" condition ") " invoke-callback-js)
invoke-callback-js))

;; A raw function, register it as callback
(fn? callback)
(str "ripley.send(" (p/register-callback! context/*live-context* callback) ", [])")

;; Some js expression, return as is
(string? callback)
callback

Expand Down Expand Up @@ -150,7 +157,7 @@
`(style->str ~new-val)
new-val)]
`(let [source# (source/source ~source)]
(when (p/immediate? source#)
(when (p/immediate? source#) ;; FIXME: don't output if value is nil
(out! " " ~(name attr) "=\"")
(let [~val (async/<!! (p/to-channel source#))
~@(when component
Expand Down

0 comments on commit c78e35b

Please sign in to comment.