Skip to content

Commit 562afa6

Browse files
committed
[electric] early detect unwatchable argument to e/watch
1 parent a7f8cba commit 562afa6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/hyperfiddle/electric3.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,16 @@ Syntax :
140140
Returns the current state of current continuous flow `cf`.
141141
" [& flows] `(join (r/fixed-signals ~@flows)))
142142

143+
(cc/defn watchable! [ref]
144+
(ca/is ref #?(:clj #(instance? clojure.lang.IRef %) :cljs #(satisfies? IWatchable %)) (str "Not watchable: " ref)))
145+
143146
(defmacro watch "
144147
Syntax :
145148
```clojure
146149
(watch !ref)
147150
```
148151
Returns the current state of current reference `!ref`.
149-
" [ref] `(check-electric watch (input (m/watch ~ref))))
152+
" [ref] `(check-electric watch (input (m/watch (watchable! ~ref)))))
150153

151154
(defmacro diff-by "
152155
Syntax :

test/hyperfiddle/electric3_test.cljc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,3 +2900,8 @@
29002900
% := [_ 1]
29012901
(hash (first *1)) := (hash (first *3)) ; not the same hash – pure got rebuilt
29022902
)))
2903+
2904+
(tests
2905+
"nice error message on non-watchable `e/watch` call"
2906+
(with ((l/single {} (e/watch :foo)) tap tap)
2907+
(str/includes? (ex-message %) "Not watchable: :foo") := true))

0 commit comments

Comments
 (0)