-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
js_builtins.cljs
52 lines (45 loc) · 1.32 KB
/
js_builtins.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
(ns shadow.remote.runtime.cljs.js-builtins
(:require
[goog.object :as gobj]
[clojure.core.protocols :as p]))
(extend-protocol p/Datafiable
;; FIXME: this is kind of a bad idea
;; can't do this for all objects, since none of the CLJS types implement this
;; protocol either. the protocol dispatch will end up using object
;; FIXME: this could detect CLJS types to some extent
;; or should it just implement the protocols for the types?
object
(datafy [o]
(if-not (identical? (.-__proto__ o) js/Object.prototype)
o
(with-meta
(->> (gobj/getKeys o)
(reduce
(fn [m key]
(assoc! m key (gobj/get o key)))
(transient {}))
(persistent!))
{`p/nav (fn [coll k v]
(gobj/get o k))})))
array
(datafy [o]
(vec o))
js/Error
(datafy [e]
(let [data (ex-data e)
file (.-fileName e)
line (.-lineNumber e)
column (.-columnNumber e)]
(-> {:message (.-message e)
:name (.-name e)
:stack (.-stack e)}
(cond->
(some? data)
(assoc :data data)
file
(assoc :file file)
line
(assoc :line line)
column
(assoc :column column)
)))))