Skip to content

Commit 7849f8d

Browse files
committed
Testing #7.
Merge remote-tracking branch 'matevarga/master' * matevarga/master: Removing ObjMap patching as it's deprecated. Fixing namespace usages. Updated cljs and clojure version. Fixed namespace of recurse-from-hyde-cache in funpatcher.cljs Fixed incorrect reference to re-matches.
2 parents 3bb15e8 + 3d69533 commit 7849f8d

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

project.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
:url "https://github.com/dribnet/mrhyde"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[org.clojure/clojure "1.5.1"]
7-
[org.clojure/clojurescript "0.0-1878"]]
6+
:dependencies [[org.clojure/clojure "1.6.0"]
7+
[org.clojure/clojurescript "0.0-2665"]]
88
:min-lein-version "2.0.0"
99
:source-paths ["src/clj" "src/cljs"]
1010

src/cljs/mrhyde/funpatcher.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns mrhyde.funpatcher
2-
(:require [mrhyde.mrhyde :refer [hyde-array? recurse-from-hyde-cache IHyde]]
2+
(:require [mrhyde.mrhyde :refer [hyde-array? IHyde]]
3+
[mrhyde.typepatcher :refer [recurse-from-hyde-cache]]
34
[mrhyde.guts :refer [get-store-cur-js-fn restore-original-js-fn
45
hyde-proto-array-marker hyde-proto-object-marker]]
56
))

src/cljs/mrhyde/mrhyde.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; providing clojure data a split personality: don't be afraid to let it all out
22
(ns mrhyde.mrhyde
3-
(:require [clojure.string :refer [join re-matches]]
3+
(:require [clojure.string :refer [join]]
44
[cljs.reader :refer [read-string]]
55
[mrhyde.guts :refer [hyde-proto-array-marker hyde-proto-object-marker]]
66
))

src/cljs/mrhyde/typepatcher.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,13 @@
527527

528528
(defn patch-known-mappish-types []
529529
(patch-sequential-type cljs.core.LazySeq) ; <-- TODO BUG - this should not be necessary!
530-
(doseq [t [[cljs.core.ObjMap, "ObjMap"]
531-
[cljs.core.PersistentHashMap, "PersistentHashMap"]
530+
(doseq [t [[cljs.core.PersistentHashMap, "PersistentHashMap"]
532531
[cljs.core.PersistentArrayMap, "PersistentArrayMap"]]]
533532
(if (= (first t) (aget cljs.core (second t)))
534533
(patch-map-type t)))
535534
; existant magic constant instances need to be patched in place...
536-
(set! cljs.core.ObjMap/EMPTY (patch-map cljs.core.ObjMap/EMPTY)))
535+
;(set! cljs.core.ObjMap/EMPTY (patch-map cljs.core.ObjMap/EMPTY))
536+
)
537537

538538
; on any object, someone somewhere is getting the parition key
539539
(defn get-partition-key []

test/cljs/mrhyde/test.cljs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
patch-args-clj-to-js]]
1313
))
1414

15-
(def DummyLib (this-as ct (aget ct "DummyLib")))
15+
;(def DummyLib (this-as ct (aget ct "DummyLib")))
16+
(def DummyLib (js-obj))
1617

1718
(defn init []
1819
; patch the dummy library
@@ -51,7 +52,7 @@
5152
(add-test "js access cljs vector as array"
5253
(fn []
5354
(let [v [1 2 3 4 5]]
54-
(assert (= 5 v/length))
55+
(assert (= 5 (.-length v)))
5556
(assert (= 1 (aget v 0)))
5657
(assert (= 3 (aget v "2")))
5758
(assert (= 5 (aget v 4)))
@@ -66,7 +67,7 @@
6667
(assert (= 1 (aget l 0)))
6768
(assert (= 21 (aget l 10)))
6869
(assert (= js/undefined (aget l 70)))
69-
(assert (= 50 l/length))
70+
(assert (= 50 (.-length l)))
7071
)))
7172

7273
(add-test "js access lazy seq of vectors as array of arrays"
@@ -80,13 +81,13 @@
8081
; (assert (js-arrays-equal (array 2 1) (aget l 5)))
8182
(assert (= js/undefined (aget l 7)))
8283
(assert (= js/undefined (aget (aget l 0) 3)))
83-
(assert (= 6 l/length))
84+
(assert (= 6 (.-length l)))
8485
)))
8586

8687
(add-test "js access maps as object fields"
8788
(fn []
8889
(let [m {:one 1 :two 2 :three 3}]
89-
(assert (= 1 m/one))
90+
(assert (= 1 (.-one m)))
9091
(assert (= 2 (aget m "two")))
9192
(assert (= 3 (.-three m)))
9293
(assert (= js/undefined (.-four m)))
@@ -101,7 +102,7 @@
101102
(fn []
102103
(let [v [1,2]
103104
m {:one 1, :two 2}
104-
[r0 r1 r2] (DummyLib/wrapArgs0and2 v m m)]
105+
[r0 r1 r2] (.wrapArgs0and2 js/DummyLib v m m)]
105106

106107
; (.log js/console r0)
107108
; (.log js/console (array 1 2))
@@ -128,10 +129,10 @@
128129

129130
(add-test "patch-return-value-to-clj"
130131
(fn []
131-
(let [ra (DummyLib/wrapReturnArgsIntoArray 0 1 2)
132-
rav (DummyLib/wrapReturnArgsIntoArray (array 0 1) (array 2 3) (array 4 5))
133-
ro (DummyLib/wrapReturnArgsIntoObject 1 2 3)
134-
rov (DummyLib/wrapReturnArgsIntoObject (array 0 1) (array 2 3) (array 4 5))]
132+
(let [ra (.wrapReturnArgsIntoArray js/DummyLib 0 1 2)
133+
rav (.wrapReturnArgsIntoArray js/DummyLib (array 0 1) (array 2 3) (array 4 5))
134+
ro (.wrapReturnArgsIntoObjectjs/DummyLib 1 2 3)
135+
rov (.wrapReturnArgsIntoObjectjs/DummyLib (array 0 1) (array 2 3) (array 4 5))]
135136

136137
; (.log js/console (str rov))
137138

@@ -151,16 +152,16 @@
151152
(let [m {:one 1 :two 2 :three 3}]
152153

153154
; check equality where you can
154-
(assert (= 1 (DummyLib/wrapCall0on1 :one m)))
155-
(assert (= 3 (DummyLib/wrapCall0on1 :three m)))
156-
(assert (= nil (DummyLib/wrapCall0on1 :four m)))
155+
(assert (= 1 (.wrapCall0on1 js/DummyLib :one m)))
156+
(assert (= 3 (.wrapCall0on1 js/DummyLib :three m)))
157+
(assert (= nil (.wrapCall0on1 js/DummyLib :four m)))
157158
)))
158159

159160
(add-test "patch everything in to-js and out to-clj"
160161
(fn []
161-
(let [ra (DummyLib/wrapArraysInAndOut 1 2 3)
162-
rav (DummyLib/wrapArraysInAndOut [0 1] [2 3] [4 5])
163-
[r1 r2 r3] (DummyLib/wrapArraysInAndOut [:a :b :c] [#{:a, :b, :c}] ["a" "b" "c"])]
162+
(let [ra (.wrapArraysInAndOut js/DummyLib 1 2 3)
163+
rav (.wrapArraysInAndOut js/DummyLib [0 1] [2 3] [4 5])
164+
[r1 r2 r3] (.wrapArraysInAndOut js/DummyLib [:a :b :c] [#{:a, :b, :c}] ["a" "b" "c"])]
164165

165166
; (.log js/console r2)
166167
; (.log js/console (str (r2 0)))
@@ -183,7 +184,7 @@
183184
(assert (hyde? v))
184185
(assert (not (has-cache? v)))
185186
(assert (= (v (from-cache v))))
186-
(let [[ra rv] (DummyLib/zeroOutFirstArrayElement v)]
187+
(let [[ra rv] (.zeroOutFirstArrayElement js/DummyLib v)]
187188
; the method thinks it changed the vector
188189
(assert (= rv 0))
189190
; locally the vector remains unchanged
@@ -204,7 +205,7 @@
204205
(assert (hyde? m))
205206
(assert (not (has-cache? m)))
206207
(assert (= (m (from-cache m))))
207-
(let [[rm rv] (DummyLib/zeroOutMapKeyOne m)]
208+
(let [[rm rv] (.zeroOutMapKeyOne js/DummyLib m)]
208209
; the method thinks it changed the map
209210
(assert (= rv 0))
210211
; locally the vector remains unchanged
@@ -225,7 +226,7 @@
225226
(assert (hyde? m))
226227
(assert (not (has-cache? m)))
227228
(assert (= (m (from-cache m))))
228-
(let [[rm rv] (DummyLib/zeroOutMapKeyTen m)]
229+
(let [[rm rv] (.zeroOutMapKeyTen js/DummyLib m)]
229230
; (-> js/fdebug (set! m))
230231
; (-> js/gdebug (set! rm))
231232
; (-> js/has (set! has-cache?))
@@ -249,8 +250,8 @@
249250
(assert (hyde? m))
250251
(assert (not (has-cache? m)))
251252
(assert (= (m (from-cache m))))
252-
(let [[rm1 rv1] (DummyLib/zeroOutMapKeyOne m)
253-
[rm2 rv2] (DummyLib/zeroOutMapKeyTen rm1)]
253+
(let [[rm1 rv1] (.zeroOutMapKeyOne js/DummyLib m)
254+
[rm2 rv2] (.zeroOutMapKeyTen js/DummyLib rm1)]
254255
; remote additons to the maps
255256
(assert (= rv1 0))
256257
(assert (= rv2 0))
@@ -284,10 +285,10 @@
284285
(assert (not (has-cache? d)))
285286
(let [
286287
;[rm1 rv1] (DummyLib/zeroOutFirstArrayElement d)
287-
[rm2 rv2] (DummyLib/zeroOutMapKeyOne (nth d 2))
288-
[rm3 rv3] (DummyLib/zeroOutMapKeyTen (nth d 2))
289-
[rm4 rv4] (DummyLib/zeroOutFirstArrayElement (get-in d [2 :vec]))
290-
[rm5 rv5] (DummyLib/zeroOutFirstArrayElement (get-in d [2 :vec 2]))]
288+
[rm2 rv2] (.zeroOutMapKeyOne js/DummyLib (nth d 2))
289+
[rm3 rv3] (.zeroOutMapKeyTen js/DummyLib (nth d 2))
290+
[rm4 rv4] (.zeroOutFirstArrayElement js/DummyLib (get-in d [2 :vec]))
291+
[rm5 rv5] (.zeroOutFirstArrayElement js/DummyLib (get-in d [2 :vec 2]))]
291292

292293
; cache information is only known locally
293294
(assert (not (has-cache? d)))
@@ -299,7 +300,7 @@
299300
; (-> js/fdebug3 (set! (nth d 2)))
300301
; (.log js/console (str (recurse-from-hyde-cache d)))
301302

302-
(assert (=
303+
(assert (=
303304
(recurse-from-hyde-cache d)
304305
[ {:bye 1, :now 2, :zero 3}
305306
{:two [], :three 3}
@@ -341,7 +342,7 @@
341342

342343
; (add-test "js->clj with cycle?"
343344
; (fn []
344-
; (let [a (js-obj) b (js-obj)] (set! (.-a b) a) (set! (.-b a) b) (js->clj a)) ; #cljs surprise of the day
345+
; (let [a (js-obj) b (js-obj)] (set! (.-a b) a) (set! (.-b a) b) (js->clj a)) ; #cljs surprise of the day
345346
; (let [c (js->clj js/p)])))
346347
; ))
347348

0 commit comments

Comments
 (0)