Revert to not munging names in interop

This commit is contained in:
Dan Holmsand 2015-10-11 13:26:43 +02:00
parent 06973350da
commit cdea2257f2
2 changed files with 9 additions and 59 deletions

View File

@ -20,33 +20,9 @@
names (-> (if (symbol? member)
(string/replace n #"^-" "")
n)
(string/split #"\."))
names (map munge names)]
(string/split #"\."))]
[field? names]))
(defmacro obj
"Create a javascript object in a Closure-safe way. The arguments
are expected to be key-value pairs, where the keys should be either
keywords or strings.
(obj :foo 1)
is equivalent to
(let [o (js-obj)]
(set! (.-foo o) 1)
o)
except that it gives the same result under advanced compilation."
[& args]
(assert (= 0 (mod (count args) 2))
"Even number of arguments expected")
(let [munged (map-indexed (fn [i x]
(if (odd? i)
x
(if (keyword? x)
(munge (name x))
x)))
args)]
`(cljs.core/js-obj ~@munged)))
(defmacro .'
"Access member in a javascript object, in a Closure-safe way.
'member' is assumed to be a field if it is a keyword or if

View File

@ -1,29 +1,26 @@
(ns reagenttest.testinterop
(:require [cljs.test :as t :refer-macros [is deftest]]
[reagent.debug :refer-macros [dbg]]
[reagent.interop :refer-macros [.' .! obj]]))
[reagent.interop :refer-macros [.' .!]]))
(def is-adv (let [o #js{}]
(set! (.-somethinglong o) true)
(not= (aget (.keys js/Object o) 0) "somethinglong")))
;; (def is-adv (let [o #js{}]
;; (set! (.-somethinglong o) true)
;; (not= (aget (.keys js/Object o) 0) "somethinglong")))
(deftest iterop-quote
(let [o (obj :foo "foo"
:foobar (obj :bar "bar"
:bar-foo "bar-foo")
:bar-foo "barfoo")]
(let [o #js{:foo "foo"
:foobar #js{:bar "bar"
:bar-foo "bar-foo"}
:bar-foo "barfoo"}]
(is (= "foo" (.' o :foo)))
(is (= "bar" (.' o :foobar.bar)))
(is (= "barfoo" (.' o :bar-foo)))
(when-not is-adv
(is (= "barfoo" (.-bar-foo o))))
(is (= "foo" (.' o -foo)))
(is (= "bar" (.' o -foobar.bar)))
(is (= "bar-foo" (.' o -foobar.bar-foo)))
(is (= "bar-foo" (.' o :foobar.bar-foo)))
(is (= "barfoo" (.' o -bar-foo)))
(.! o :foo "foo1")
(is (= "foo1" (.' o :foo)))
@ -57,26 +54,3 @@
(is (= "1bar2" (.' (.' o :foo)
call o 1)))))
(deftest interop-munge
(let [o (obj :foo-bar "foo-bar"
:foo? "foo?"
:foo$ "foo$"
:foo! "foo!"
:foo><*+% "foo><*+%")]
(is (= (.' o :foo-bar) "foo-bar"))
(is (= (.' o :foo?) "foo?"))
(is (= (.' o :foo$) "foo$"))
(is (= (.' o -foo!) "foo!"))
(is (= (.' o :foo><*+%) "foo><*+%"))
(when-not is-adv
(is (= (.-foo-bar o) "foo-bar"))
(is (= (.-foo? o) "foo?"))
(is (= (.-foo$ o) "foo$"))
(is (= (.-foo><*+% o) "foo><*+%"))
(let [x (js-obj)]
(.! x -foo-bar "foo-bar")
(is (= (.-foo-bar x) "foo-bar"))
(set! (.-foo? x) "foo?")
(is (= (.' x :foo?) "foo?"))))))