-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_path.cljc
51 lines (43 loc) · 1.32 KB
/
data_path.cljc
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
(ns prpr3.a-frame.interceptor-chain.data.data-path
(:require
#?(:clj [clojure.pprint :as pprint])
[prpr3.a-frame.interceptor-chain.data.protocols :as p]
[taoensso.timbre :refer [info warn]]))
;; this protocol is for the cljs IPrintWithWriter
;; method, because there is no .path getter
;; wiht a cljs deftype
(defprotocol IDataPath
(-path [_]))
;; don't know why, but cljs compile doesn't agree
;; with deftype here - probably some badly
;; documented interaction with the tag-readers
(defrecord DataPath [path]
p/IResolveData
(-resolve-data [_spec interceptor-ctx]
(let [data (get-in interceptor-ctx path)]
;; (warn "resolve DataPath" path)
data))
IDataPath
(-path [_]
path))
#?(:clj
(defn print-data-path
[dp ^java.io.Writer w]
(.write w "#prpr3.ctx/path ")
(print-method (-path dp) w)))
#?(:clj
(defmethod print-method DataPath [this ^java.io.Writer w]
(print-data-path this w)))
#?(:clj
(defmethod print-dup DataPath [this ^java.io.Writer w]
(print-data-path this w)))
#?(:clj
(.addMethod pprint/simple-dispatch
DataPath
(fn [dp]
(print-data-path dp *out*))))
#?(:cljs
(extend-protocol IPrintWithWriter
DataPath
(-pr-writer [dp writer _]
(write-all writer "#prpr3.ctx/path " (-path dp) ""))))