Tag all objects with infer warnings

This commit is contained in:
Juho Teperi 2019-10-25 10:25:43 +03:00
parent d663f3b53e
commit a9cace4e14
6 changed files with 33 additions and 33 deletions

View File

@ -24,7 +24,7 @@
fake-raf)))) fake-raf))))
(defn compare-mount-order (defn compare-mount-order
[c1 c2] [^clj c1 ^clj c2]
;; Mount order is now set in DidMount method. I.e. the ;; Mount order is now set in DidMount method. I.e. the
;; top-most component is mounted last and gets largest ;; top-most component is mounted last and gets largest
;; number. This is reverse compared to WillMount where method ;; number. This is reverse compared to WillMount where method
@ -49,7 +49,7 @@
(dotimes [i (alength fs)] (dotimes [i (alength fs)]
((aget fs i)))) ((aget fs i))))
(defn enqueue [queue fs f] (defn enqueue [^clj queue fs f]
(assert-some f "Enqueued function") (assert-some f "Enqueued function")
(.push fs f) (.push fs f)
(.schedule queue)) (.schedule queue))
@ -109,12 +109,12 @@
(defn flush-after-render [] (defn flush-after-render []
(.flush-after-render render-queue)) (.flush-after-render render-queue))
(defn queue-render [c] (defn queue-render [^clj c]
(when-not (.-cljsIsDirty c) (when-not (.-cljsIsDirty c)
(set! (.-cljsIsDirty c) true) (set! (.-cljsIsDirty c) true)
(.queue-render render-queue c))) (.queue-render render-queue c)))
(defn mark-rendered [c] (defn mark-rendered [^clj c]
(set! (.-cljsIsDirty c) false)) (set! (.-cljsIsDirty c) false))
(defn do-before-flush [f] (defn do-before-flush [f]

View File

@ -64,19 +64,19 @@
(and (fn? c) (and (fn? c)
(some? (some-> c (.-prototype) (.-render))))) (some? (some-> c (.-prototype) (.-render)))))
(defn ^boolean reagent-component? [c] (defn ^boolean reagent-component? [^clj c]
(some? (.-reagentRender c))) (some? (.-reagentRender c)))
(defn cached-react-class [c] (defn cached-react-class [^clj c]
(.-cljsReactClass c)) (.-cljsReactClass c))
(defn cache-react-class [c constructor] (defn cache-react-class [^clj c constructor]
(set! (.-cljsReactClass c) constructor)) (set! (.-cljsReactClass c) constructor))
;;; State ;;; State
(defn state-atom [this] (defn state-atom [^clj this]
(let [sa (.-cljsState this)] (let [sa (.-cljsState this)]
(if-not (nil? sa) (if-not (nil? sa)
sa sa
@ -95,7 +95,7 @@
2) Function (form-2 component) - updates the render function to `res` i.e. the internal function 2) Function (form-2 component) - updates the render function to `res` i.e. the internal function
and calls wrap-render again (`recur`), until the render result doesn't evaluate to a function. and calls wrap-render again (`recur`), until the render result doesn't evaluate to a function.
3) Anything else - Returns the result of evaluating `c`" 3) Anything else - Returns the result of evaluating `c`"
[c] [^clj c]
(let [f (.-reagentRender c) (let [f (.-reagentRender c)
_ (assert-callable f) _ (assert-callable f)
;; cljsLegacyRender tells if this calls was defined ;; cljsLegacyRender tells if this calls was defined
@ -150,7 +150,7 @@
;; TODO: Use static property for cljsRatom ;; TODO: Use static property for cljsRatom
(this-as c (if util/*non-reactive* (this-as c (if util/*non-reactive*
(do-render c) (do-render c)
(let [rat (gobj/get c "cljsRatom")] (let [^clj rat (gobj/get c "cljsRatom")]
(batch/mark-rendered c) (batch/mark-rendered c)
(if (nil? rat) (if (nil? rat)
(ratom/run-in-reaction #(do-render c) c "cljsRatom" (ratom/run-in-reaction #(do-render c) c "cljsRatom"
@ -232,7 +232,7 @@
(this-as c (this-as c
;; This method is called after everything inside the ;; This method is called after everything inside the
;; has been mounted. This is reverse compared to WillMount. ;; has been mounted. This is reverse compared to WillMount.
(set! (.-cljsMountOrder c) (batch/next-mount-count)) (set! (.-cljsMountOrder ^clj c) (batch/next-mount-count))
(when-not (nil? f) (when-not (nil? f)
(.call f c c)))) (.call f c c))))
@ -347,13 +347,13 @@
;; These names SHOULD be mangled by Closure so we can't use goog/extend ;; These names SHOULD be mangled by Closure so we can't use goog/extend
(when (:render body) (when (:render body)
(set! (.-render (.-prototype cmp)) (:render body))) (set! (.-render ^js (.-prototype cmp)) (:render body)))
(when (:reagentRender body) (when (:reagentRender body)
(set! (.-reagentRender (.-prototype cmp)) (:reagentRender body))) (set! (.-reagentRender ^clj (.-prototype cmp)) (:reagentRender body)))
(when (:cljsLegacyRender body) (when (:cljsLegacyRender body)
(set! (.-cljsLegacyRender (.-prototype cmp)) (:cljsLegacyRender body))) (set! (.-cljsLegacyRender ^clj (.-prototype cmp)) (:cljsLegacyRender body)))
(gobj/extend cmp react/Component static-methods) (gobj/extend cmp react/Component static-methods)

View File

@ -112,7 +112,7 @@
class class
(assoc :class (util/class-names class (:class props)))))) (assoc :class (util/class-names class (:class props))))))
(defn convert-props [props id-class] (defn convert-props [props ^clj id-class]
(let [class (:class props) (let [class (:class props)
props (-> props props (-> props
(cond-> class (assoc :class (util/class-names class))) (cond-> class (assoc :class (util/class-names class)))
@ -139,7 +139,7 @@
(declare input-component-set-value) (declare input-component-set-value)
(defn input-node-set-value (defn input-node-set-value
[node rendered-value dom-value component {:keys [on-write]}] [node rendered-value dom-value ^clj component {:keys [on-write]}]
(if-not (and (identical? node (.-activeElement js/document)) (if-not (and (identical? node (.-activeElement js/document))
(has-selection-api? (.-type node)) (has-selection-api? (.-type node))
(string? rendered-value) (string? rendered-value)
@ -187,7 +187,7 @@
(set! (.-selectionStart node) new-cursor-offset) (set! (.-selectionStart node) new-cursor-offset)
(set! (.-selectionEnd node) new-cursor-offset)))))) (set! (.-selectionEnd node) new-cursor-offset))))))
(defn input-component-set-value [this] (defn input-component-set-value [^clj this]
(when (.-cljsInputLive this) (when (.-cljsInputLive this)
(set! (.-cljsInputDirty this) false) (set! (.-cljsInputDirty this) false)
(let [rendered-value (.-cljsRenderedValue this) (let [rendered-value (.-cljsRenderedValue this)
@ -197,7 +197,7 @@
(when (not= rendered-value dom-value) (when (not= rendered-value dom-value)
(input-node-set-value node rendered-value dom-value this {}))))) (input-node-set-value node rendered-value dom-value this {})))))
(defn input-handle-change [this on-change e] (defn input-handle-change [^clj this on-change e]
(set! (.-cljsDOMValue this) (-> e .-target .-value)) (set! (.-cljsDOMValue this) (-> e .-target .-value))
;; Make sure the input is re-rendered, in case on-change ;; Make sure the input is re-rendered, in case on-change
;; wants to keep the value unchanged ;; wants to keep the value unchanged
@ -207,7 +207,7 @@
(on-change e)) (on-change e))
(defn input-render-setup (defn input-render-setup
[this jsprops] [^clj this ^js jsprops]
;; Don't rely on React for updating "controlled inputs", since it ;; Don't rely on React for updating "controlled inputs", since it
;; doesn't play well with async rendering (misses keystrokes). ;; doesn't play well with async rendering (misses keystrokes).
(when (and (some? jsprops) (when (and (some? jsprops)
@ -227,7 +227,7 @@
(set! (.-defaultValue jsprops) value) (set! (.-defaultValue jsprops) value)
(set! (.-onChange jsprops) #(input-handle-change this on-change %))))) (set! (.-onChange jsprops) #(input-handle-change this on-change %)))))
(defn input-unmount [this] (defn input-unmount [^clj this]
(set! (.-cljsInputLive this) nil)) (set! (.-cljsInputLive this) nil))
(defn ^boolean input-component? [x] (defn ^boolean input-component? [x]
@ -396,7 +396,7 @@
(defn expand-seq [s] (defn expand-seq [s]
(into-array (map as-element s))) (into-array (map as-element s)))
(defn expand-seq-dev [s o] (defn expand-seq-dev [s ^clj o]
(into-array (map (fn [val] (into-array (map (fn [val]
(when (and (vector? val) (when (and (vector? val)
(nil? (key-from-vec val))) (nil? (key-from-vec val)))

View File

@ -107,7 +107,7 @@
(-invoke [_ a b c d e f g h i j k l m n o p q r s t rest] (-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)) (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 [_ ^clj other]
(and (instance? PartialFn other) (and (instance? PartialFn other)
(= f (.-f other)) (= f (.-f other))
(= args (.-args other)))) (= args (.-args other))))

View File

@ -47,7 +47,7 @@
Inside '_update-watching' along with adding the ratoms in 'r.watching' of reaction, Inside '_update-watching' along with adding the ratoms in 'r.watching' of reaction,
the reaction is also added to the list of watches on each ratoms f derefs." the reaction is also added to the list of watches on each ratoms f derefs."
[f r] [f ^clj r]
(set! (.-captured r) nil) (set! (.-captured r) nil)
(when (dev?) (when (dev?)
(set! (.-ratomGeneration r) (set! generation (inc generation)))) (set! (.-ratomGeneration r) (set! generation (inc generation))))
@ -75,17 +75,17 @@
(swap! -running + (- (count new) (count old)))) (swap! -running + (- (count new) (count old))))
new) new)
(defn- add-w [this key f] (defn- add-w [^clj this key f]
(let [w (.-watches this)] (let [w (.-watches this)]
(set! (.-watches this) (check-watches w (assoc w key f))) (set! (.-watches this) (check-watches w (assoc w key f)))
(set! (.-watchesArr this) nil))) (set! (.-watchesArr this) nil)))
(defn- remove-w [this key] (defn- remove-w [^clj this key]
(let [w (.-watches this)] (let [w (.-watches this)]
(set! (.-watches this) (check-watches w (dissoc w key))) (set! (.-watches this) (check-watches w (dissoc w key)))
(set! (.-watchesArr this) nil))) (set! (.-watchesArr this) nil)))
(defn- notify-w [this old new] (defn- notify-w [^clj this old new]
(let [w (.-watchesArr this) (let [w (.-watchesArr this)
a (if (nil? w) a (if (nil? w)
;; Copy watches to array for speed ;; Copy watches to array for speed
@ -188,7 +188,7 @@
(declare make-reaction) (declare make-reaction)
(defn- cached-reaction [f o k obj destroy] (defn- cached-reaction [f ^clj o k ^clj obj destroy]
(let [m (.-reagReactionCache o) (let [m (.-reagReactionCache o)
m (if (nil? m) {} m) m (if (nil? m) {} m)
r (m k nil)] r (m k nil)]
@ -222,7 +222,7 @@
(cached-reaction #(apply f args) f args this nil))) (cached-reaction #(apply f args) f args this nil)))
IEquiv IEquiv
(-equiv [_ other] (-equiv [_ ^clj other]
(and (instance? Track other) (and (instance? Track other)
(= f (.-f other)) (= f (.-f other))
(= args (.-args other)))) (= args (.-args other))))
@ -259,7 +259,7 @@
IReactiveAtom IReactiveAtom
IEquiv IEquiv
(-equiv [_ other] (-equiv [_ ^clj other]
(and (instance? RCursor other) (and (instance? RCursor other)
(= path (.-path other)) (= path (.-path other))
(= ratom (.-ratom other)))) (= ratom (.-ratom other))))
@ -316,7 +316,7 @@
(-hash [_] (hash [ratom path]))) (-hash [_] (hash [ratom path])))
(defn cursor (defn cursor
[src path] [^clj src path]
(assert (or (satisfies? IReactiveAtom src) (assert (or (satisfies? IReactiveAtom src)
(and (ifn? src) (and (ifn? src)
(not (vector? src)))) (not (vector? src))))
@ -347,7 +347,7 @@
(defprotocol IRunnable (defprotocol IRunnable
(run [this])) (run [this]))
(defn- handle-reaction-change [this sender old new] (defn- handle-reaction-change [^clj this sender old new]
(._handle-change this sender old new)) (._handle-change this sender old new))
;; Fields of a Reaction javascript object ;; Fields of a Reaction javascript object
@ -578,7 +578,7 @@
(-swap! [a f x y more] (-reset! a (apply f state x y more))) (-swap! [a f x y more] (-reset! a (apply f state x y more)))
IEquiv IEquiv
(-equiv [_ other] (-equiv [_ ^clj other]
(and (instance? Wrapper other) (and (instance? Wrapper other)
;; If either of the wrappers have changed, equality ;; If either of the wrappers have changed, equality
;; cannot be relied on. ;; cannot be relied on.

View File

@ -1318,7 +1318,7 @@
:get-derived-state-from-error (fn [error] :get-derived-state-from-error (fn [error]
#js {:hasError true}) #js {:hasError true})
:component-did-catch (fn [this e info]) :component-did-catch (fn [this e info])
:render (fn [this] :render (fn [^js/React.Component this]
(r/as-element (if (.-hasError (.-state this)) (r/as-element (if (.-hasError (.-state this))
[:p "Error"] [:p "Error"]
(into [:<>] (r/children this)))))}) (into [:<>] (r/children this)))))})