Skip to content

Commit 65945bb

Browse files
committed
better docstring w/ examples
1 parent 1928849 commit 65945bb

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/main/cljs/cljs/proxy.cljs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,29 @@
1616
:enumerable true})
1717

1818
(defn builder
19-
"EXPERIMENTAL: Return a JavaScript Proxy ctor fn with the provided key-fn. You
20-
can proxy ClojureScript map and vectors. Access pattern from JavaScript
21-
will lazily wrap collection values in Proxy if needed. Note key-fn
22-
is only used for proxied ClojureScript maps. This function should map
23-
strings to the appropriate key representation. All maps proxied from the
24-
same ctor fn will share the same key-fn cache."
19+
"EXPERIMENTAL: Returns a JavaScript Proxy ctor fn with the provided
20+
key-fn. Invoking the returned fn on ClojureScript maps and vectors
21+
will returned proxied values that can be used transparently as
22+
JavaScript objects and arrays:
23+
24+
(def proxy (builder))
25+
26+
(def proxied-map (proxy {:foo 1 :bar 2}))
27+
(goog.object/get proxied-map \"foo\") ;; => 1
28+
29+
(def proxied-vec (proxy [1 2 3 4]))
30+
(aget proxied-vec 1) ;; => 2
31+
32+
Access patterns from JavaScript on these proxied values will lazily
33+
recursively return further proxied values:
34+
35+
(def nested-proxies (proxy [{:foo 1 :bar 2}]))
36+
(-> nested-proxies (aget 0) (goog.object/get \"foo\")) ;; => 1
37+
38+
Note key-fn is only used for proxied ClojureScript maps. This
39+
function should map strings to the appropriate key
40+
representation. All maps proxied from the same ctor fn will share
41+
the same key-fn cache."
2542
([]
2643
(builder keyword))
2744
([key-fn]

0 commit comments

Comments
 (0)