2015-02-10 13:18:56 +00:00
|
|
|
(ns reagenttest.testinterop
|
2015-01-31 22:09:42 +00:00
|
|
|
(:require [cljs.test :as t :refer-macros [is deftest]]
|
2014-03-14 09:27:49 +00:00
|
|
|
[reagent.debug :refer-macros [dbg]]
|
2015-10-22 11:23:49 +00:00
|
|
|
[reagent.interop :refer-macros [$ $!]]))
|
2014-03-14 09:27:49 +00:00
|
|
|
|
2015-10-11 11:26:43 +00:00
|
|
|
;; (def is-adv (let [o #js{}]
|
|
|
|
;; (set! (.-somethinglong o) true)
|
|
|
|
;; (not= (aget (.keys js/Object o) 0) "somethinglong")))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
|
|
|
(deftest iterop-quote
|
2015-10-11 11:26:43 +00:00
|
|
|
(let [o #js{:foo "foo"
|
|
|
|
:foobar #js{:bar "bar"
|
|
|
|
:bar-foo "bar-foo"}
|
|
|
|
:bar-foo "barfoo"}]
|
2015-09-25 09:48:50 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
(is (= "foo" ($ o :foo)))
|
|
|
|
(is (= "bar" ($ o :foobar.bar)))
|
|
|
|
(is (= "barfoo" ($ o :bar-foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
(is (= "foo" ($ o -foo)))
|
|
|
|
(is (= "bar" ($ o -foobar.bar)))
|
|
|
|
(is (= "bar-foo" ($ o -foobar.bar-foo)))
|
|
|
|
(is (= "bar-foo" ($ o :foobar.bar-foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
($! o :foo "foo1")
|
|
|
|
(is (= "foo1" ($ o :foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
($! o -foo "foo2")
|
|
|
|
(is (= "foo2" ($ o -foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
($! o :foobar.bar "bar1")
|
|
|
|
(is (= "bar1" ($ o :foobar.bar)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
($! o -foobar.bar "bar1")
|
|
|
|
(is (= "bar1" ($ o -foobar.bar)))))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
|
|
|
(deftest interop-quote-call
|
|
|
|
(let [o #js{:bar "bar1"
|
|
|
|
:foo (fn [x]
|
|
|
|
(this-as this
|
2015-10-22 11:23:49 +00:00
|
|
|
(str x ($ this :bar))))}
|
2014-03-25 06:58:22 +00:00
|
|
|
o2 #js{:o o}]
|
2015-10-22 11:23:49 +00:00
|
|
|
(is (= "ybar1" ($ o foo "y")))
|
|
|
|
(is (= "xxbar1" ($ o2 o.foo "xx")))
|
2014-03-25 06:58:22 +00:00
|
|
|
(is (= "abar1" (-> o2
|
2015-10-22 11:23:49 +00:00
|
|
|
($ :o)
|
|
|
|
($ foo "a"))))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
(is (= "bar1" ($ o foo)))
|
|
|
|
(is (= "bar1" ($ o2 o.foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
($! o :bar "bar2")
|
|
|
|
(is (= "bar2" ($ o foo)))
|
2014-03-25 06:58:22 +00:00
|
|
|
|
2015-10-22 11:23:49 +00:00
|
|
|
(is (= "1bar2" ($ ($ o :foo)
|
2014-03-25 06:58:22 +00:00
|
|
|
call o 1)))))
|