-
Notifications
You must be signed in to change notification settings - Fork 4
/
macro.clj
33 lines (29 loc) · 847 Bytes
/
macro.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns cuic.impl.macro
(:require [cuic.impl.dom-node :refer [maybe existing]]
[cuic.impl.exception :as ex]
[cuic.impl.js-bridge :as js])
(:import (cuic ExecutionException)))
(defmacro ignore-stale [expr]
`(try
~expr
(catch ExecutionException e#
(if-not (ex/stale-node? e#) (throw e#))
nil)))
(defmacro let-some
[[binding expr] & body]
`(if-let [~binding (maybe ~expr)]
~@body))
(defmacro let-existing
{:style/indent 0}
[[binding expr] & body]
{:pre [(symbol? binding)]}
`(let [~binding (existing ~expr)]
~@body))
(defmacro let-visible
{:style/indent 0}
[[binding expr] & body]
{:pre [(symbol? binding)]}
`(let [~binding (existing ~expr)]
(if-not (js/eval-in ~binding "!!this.offsetParent")
(throw (ex/retryable "Node is not visible")))
~@body))