mirror of https://github.com/status-im/reagent.git
Merge pull request #303 from reagent-project/fix-partial-ifn
Fix partial-ifn with latest Cljs
This commit is contained in:
commit
8f2f967f80
|
@ -4,7 +4,7 @@
|
||||||
:description "A simple ClojureScript interface to React"
|
:description "A simple ClojureScript interface to React"
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.8.0"]
|
:dependencies [[org.clojure/clojure "1.8.0"]
|
||||||
[org.clojure/clojurescript "1.8.51"]
|
[org.clojure/clojurescript "1.9.655"]
|
||||||
[cljsjs/react-dom "15.5.4-0"]
|
[cljsjs/react-dom "15.5.4-0"]
|
||||||
[cljsjs/react-dom-server "15.5.4-0"]
|
[cljsjs/react-dom-server "15.5.4-0"]
|
||||||
[cljsjs/create-react-class "15.5.3-0"]]
|
[cljsjs/create-react-class "15.5.3-0"]]
|
||||||
|
|
|
@ -337,10 +337,9 @@
|
||||||
(batch/do-after-render f))
|
(batch/do-after-render f))
|
||||||
|
|
||||||
(defn partial
|
(defn partial
|
||||||
"Works just like clojure.core/partial, except that it is an IFn, and
|
"Works just like clojure.core/partial, but the result can be compared with ="
|
||||||
the result can be compared with ="
|
|
||||||
[f & args]
|
[f & args]
|
||||||
(util/partial-ifn. f args nil))
|
(util/make-partial-fn f args))
|
||||||
|
|
||||||
(defn component-path
|
(defn component-path
|
||||||
;; Try to return the path of component c as a string.
|
;; Try to return the path of component c as a string.
|
||||||
|
|
|
@ -65,17 +65,62 @@
|
||||||
str
|
str
|
||||||
(clojure.string/replace "$" "."))))
|
(clojure.string/replace "$" "."))))
|
||||||
|
|
||||||
(deftype partial-ifn [f args ^:mutable p]
|
(deftype PartialFn [pfn f args]
|
||||||
|
Fn
|
||||||
IFn
|
IFn
|
||||||
(-invoke [_ & a]
|
(-invoke [_]
|
||||||
(or p (set! p (apply clojure.core/partial f args)))
|
(pfn))
|
||||||
(apply p a))
|
(-invoke [_ a]
|
||||||
|
(pfn a))
|
||||||
|
(-invoke [_ a b]
|
||||||
|
(pfn a b))
|
||||||
|
(-invoke [_ a b c]
|
||||||
|
(pfn a b c))
|
||||||
|
(-invoke [_ a b c d]
|
||||||
|
(pfn a b c d))
|
||||||
|
(-invoke [_ a b c d e]
|
||||||
|
(pfn a b c d e))
|
||||||
|
(-invoke [_ a b c d e f]
|
||||||
|
(pfn a b c d e f))
|
||||||
|
(-invoke [_ a b c d e f g]
|
||||||
|
(pfn a b c d e f g))
|
||||||
|
(-invoke [_ a b c d e f g h]
|
||||||
|
(pfn a b c d e f g h))
|
||||||
|
(-invoke [_ a b c d e f g h i]
|
||||||
|
(pfn a b c d e f g h i))
|
||||||
|
(-invoke [_ a b c d e f g h i j]
|
||||||
|
(pfn a b c d e f g h i j))
|
||||||
|
(-invoke [_ a b c d e f g h i j k]
|
||||||
|
(pfn a b c d e f g h i j k))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l]
|
||||||
|
(pfn a b c d e f g h i j k l))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m]
|
||||||
|
(pfn a b c d e f g h i j k l m))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n]
|
||||||
|
(pfn a b c d e f g h i j k l m n))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o]
|
||||||
|
(pfn a b c d e f g h i j k l m n o))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p]
|
||||||
|
(pfn a b c d e f g h i j k l m n o p))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p q]
|
||||||
|
(pfn a b c d e f g h i j k l m n o p q))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p q r]
|
||||||
|
(pfn a b c d e f g h i j k l m n o p q r))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p q r s]
|
||||||
|
(pfn a b c d e f g h i j k l m n o p q r s))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p q r s t]
|
||||||
|
(pfn a b c d e f g h i j k l m n o p q r s t))
|
||||||
|
(-invoke [_ a b c d e f g h i j k l m n o p q r s t rest]
|
||||||
|
(apply pfn a b c d e f g h i j k l m n o p q r s t rest))
|
||||||
IEquiv
|
IEquiv
|
||||||
(-equiv [_ other]
|
(-equiv [_ other]
|
||||||
(and (= f (.-f other)) (= args (.-args other))))
|
(and (= f (.-f other)) (= args (.-args other))))
|
||||||
IHash
|
IHash
|
||||||
(-hash [_] (hash [f args])))
|
(-hash [_] (hash [f args])))
|
||||||
|
|
||||||
|
(defn make-partial-fn [f args]
|
||||||
|
(->PartialFn (apply partial f args) f args))
|
||||||
|
|
||||||
(defn- merge-class [p1 p2]
|
(defn- merge-class [p1 p2]
|
||||||
(let [class (when-let [c1 (:class p1)]
|
(let [class (when-let [c1 (:class p1)]
|
||||||
(when-let [c2 (:class p2)]
|
(when-let [c2 (:class p2)]
|
||||||
|
|
|
@ -564,7 +564,7 @@
|
||||||
|
|
||||||
(defn make-wrapper [value callback-fn args]
|
(defn make-wrapper [value callback-fn args]
|
||||||
(->Wrapper value
|
(->Wrapper value
|
||||||
(util/->partial-ifn callback-fn args nil)
|
(util/make-partial-fn callback-fn args)
|
||||||
false nil))
|
false nil))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,8 @@
|
||||||
(is (= p1 (r/partial vector 1 2)))
|
(is (= p1 (r/partial vector 1 2)))
|
||||||
(is (ifn? p1))
|
(is (ifn? p1))
|
||||||
(is (= (r/partial vector 1 2) p1))
|
(is (= (r/partial vector 1 2) p1))
|
||||||
(is (not= p1 (r/partial vector 1 3)))))
|
(is (not= p1 (r/partial vector 1 3)))
|
||||||
|
(is (= (hash p1) (hash (r/partial vector 1 2))))))
|
||||||
|
|
||||||
(deftest test-null-component
|
(deftest test-null-component
|
||||||
(let [null-comp (fn [do-show]
|
(let [null-comp (fn [do-show]
|
||||||
|
|
Loading…
Reference in New Issue