forked from day8/re-frame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interop.cljs
58 lines (44 loc) · 1.48 KB
/
interop.cljs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(ns re-frame.interop
(:require [goog.async.nextTick]
[reagent.core]
[reagent.ratom]))
(def next-tick goog.async.nextTick)
(def empty-queue #queue [])
(def after-render reagent.core/after-render)
;; Make sure the Google Closure compiler sees this as a boolean constant,
;; otherwise Dead Code Elimination won't happen in `:advanced` builds.
;; Type hints have been liberally sprinkled.
;; https://developers.google.com/closure/compiler/docs/js-for-compiler
(def ^boolean debug-enabled? "@define {boolean}" ^boolean js/goog.DEBUG)
(defn ratom [x]
(reagent.core/atom x))
(defn ratom? [x]
(satisfies? reagent.ratom/IReactiveAtom x))
(defn deref? [x]
(satisfies? IDeref x))
(defn make-reaction [f]
(reagent.ratom/make-reaction f))
(defn add-on-dispose! [a-ratom f]
(reagent.ratom/add-on-dispose! a-ratom f))
(defn dispose! [a-ratom]
(reagent.ratom/dispose! a-ratom))
(defn set-timeout! [f ms]
(js/setTimeout f ms))
(defn now []
(if (and
(exists? js/performance)
(exists? js/performance.now))
(js/performance.now)
(js/Date.now)))
(defn reagent-id
"Produces an id for reactive Reagent values
e.g. reactions, ratoms, cursors."
[reactive-val]
(when (implements? reagent.ratom/IReactiveAtom reactive-val)
(str (condp instance? reactive-val
reagent.ratom/RAtom "ra"
reagent.ratom/RCursor "rc"
reagent.ratom/Reaction "rx"
reagent.ratom/Track "tr"
"other")
(hash reactive-val))))