Skip to content

Commit 54b1e33

Browse files
authored
allow cljs.proxy cache customization, provide default proxy (#300)
1 parent e3065b3 commit 54b1e33

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/cljs/cljs/proxy.cljs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@
3838
Note key-fn is only used for proxied ClojureScript maps. This
3939
function should map strings to the appropriate key
4040
representation. If unspecified, key-fn defaults to keyword. All maps
41-
proxied from the same ctor fn will share the same key-fn cache."
41+
proxied from the same ctor fn will share the same key-fn cache.
42+
43+
A cache-fn may be suppled to override the default cache. This fn
44+
should take key-fn and return a memoized version."
4245
([]
4346
(builder keyword))
4447
([key-fn]
48+
(builder keyword write-through))
49+
([key-fn cache-fn]
4550
(js* "var __ctor")
46-
(let [cache-key-fn (write-through key-fn)
51+
(let [cache-key-fn (cache-fn key-fn)
4752
vec-handler #js {:get (fn [^cljs.core/IIndexed target prop receiver]
4853
(cond
4954
(identical? "length" prop)
@@ -106,6 +111,9 @@
106111
:else target))]
107112
__ctor)))
108113

114+
(def ^{:doc "Default proxy for maps and vectors."}
115+
proxy (builder))
116+
109117
(comment
110118

111119
(def c (SimpleCache. #js {} 0))

0 commit comments

Comments
 (0)