diff --git a/src/reagent/impl/batching.cljs b/src/reagent/impl/batching.cljs index ba6ee35..53c1fc7 100644 --- a/src/reagent/impl/batching.cljs +++ b/src/reagent/impl/batching.cljs @@ -24,7 +24,7 @@ fake-raf)))) (defn compare-mount-order - [c1 c2] + [^clj c1 ^clj c2] ;; Mount order is now set in DidMount method. I.e. the ;; top-most component is mounted last and gets largest ;; number. This is reverse compared to WillMount where method @@ -49,7 +49,7 @@ (dotimes [i (alength fs)] ((aget fs i)))) -(defn enqueue [queue fs f] +(defn enqueue [^clj queue fs f] (assert-some f "Enqueued function") (.push fs f) (.schedule queue)) @@ -109,12 +109,12 @@ (defn flush-after-render [] (.flush-after-render render-queue)) -(defn queue-render [c] +(defn queue-render [^clj c] (when-not (.-cljsIsDirty c) (set! (.-cljsIsDirty c) true) (.queue-render render-queue c))) -(defn mark-rendered [c] +(defn mark-rendered [^clj c] (set! (.-cljsIsDirty c) false)) (defn do-before-flush [f] diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index b571c28..5ab6393 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -64,19 +64,19 @@ (and (fn? c) (some? (some-> c (.-prototype) (.-render))))) -(defn ^boolean reagent-component? [c] +(defn ^boolean reagent-component? [^clj c] (some? (.-reagentRender c))) -(defn cached-react-class [c] +(defn cached-react-class [^clj c] (.-cljsReactClass c)) -(defn cache-react-class [c constructor] +(defn cache-react-class [^clj c constructor] (set! (.-cljsReactClass c) constructor)) ;;; State -(defn state-atom [this] +(defn state-atom [^clj this] (let [sa (.-cljsState this)] (if-not (nil? sa) sa @@ -95,7 +95,7 @@ 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. 3) Anything else - Returns the result of evaluating `c`" - [c] + [^clj c] (let [f (.-reagentRender c) _ (assert-callable f) ;; cljsLegacyRender tells if this calls was defined @@ -150,7 +150,7 @@ ;; TODO: Use static property for cljsRatom (this-as c (if util/*non-reactive* (do-render c) - (let [rat (gobj/get c "cljsRatom")] + (let [^clj rat (gobj/get c "cljsRatom")] (batch/mark-rendered c) (if (nil? rat) (ratom/run-in-reaction #(do-render c) c "cljsRatom" @@ -232,7 +232,7 @@ (this-as c ;; This method is called after everything inside the ;; 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) (.call f c c)))) @@ -347,13 +347,13 @@ ;; These names SHOULD be mangled by Closure so we can't use goog/extend (when (:render body) - (set! (.-render (.-prototype cmp)) (:render body))) + (set! (.-render ^js (.-prototype cmp)) (:render body))) (when (:reagentRender body) - (set! (.-reagentRender (.-prototype cmp)) (:reagentRender body))) + (set! (.-reagentRender ^clj (.-prototype cmp)) (:reagentRender body))) (when (:cljsLegacyRender body) - (set! (.-cljsLegacyRender (.-prototype cmp)) (:cljsLegacyRender body))) + (set! (.-cljsLegacyRender ^clj (.-prototype cmp)) (:cljsLegacyRender body))) (gobj/extend cmp react/Component static-methods) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index bba707b..7f3f427 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -112,7 +112,7 @@ class (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) props (-> props (cond-> class (assoc :class (util/class-names class))) @@ -139,7 +139,7 @@ (declare input-component-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)) (has-selection-api? (.-type node)) (string? rendered-value) @@ -187,7 +187,7 @@ (set! (.-selectionStart 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) (set! (.-cljsInputDirty this) false) (let [rendered-value (.-cljsRenderedValue this) @@ -197,7 +197,7 @@ (when (not= rendered-value dom-value) (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)) ;; Make sure the input is re-rendered, in case on-change ;; wants to keep the value unchanged @@ -207,7 +207,7 @@ (on-change e)) (defn input-render-setup - [this jsprops] + [^clj this ^js jsprops] ;; Don't rely on React for updating "controlled inputs", since it ;; doesn't play well with async rendering (misses keystrokes). (when (and (some? jsprops) @@ -227,7 +227,7 @@ (set! (.-defaultValue jsprops) value) (set! (.-onChange jsprops) #(input-handle-change this on-change %))))) -(defn input-unmount [this] +(defn input-unmount [^clj this] (set! (.-cljsInputLive this) nil)) (defn ^boolean input-component? [x] @@ -396,7 +396,7 @@ (defn expand-seq [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] (when (and (vector? val) (nil? (key-from-vec val))) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index f51b418..7712c96 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -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] (apply pfn a b c d e f g h i j k l m n o p q r s t rest)) IEquiv - (-equiv [_ other] + (-equiv [_ ^clj other] (and (instance? PartialFn other) (= f (.-f other)) (= args (.-args other)))) diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 1974fa5..37885fd 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -47,7 +47,7 @@ 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." - [f r] + [f ^clj r] (set! (.-captured r) nil) (when (dev?) (set! (.-ratomGeneration r) (set! generation (inc generation)))) @@ -75,17 +75,17 @@ (swap! -running + (- (count new) (count old)))) new) -(defn- add-w [this key f] +(defn- add-w [^clj this key f] (let [w (.-watches this)] (set! (.-watches this) (check-watches w (assoc w key f))) (set! (.-watchesArr this) nil))) -(defn- remove-w [this key] +(defn- remove-w [^clj this key] (let [w (.-watches this)] (set! (.-watches this) (check-watches w (dissoc w key))) (set! (.-watchesArr this) nil))) -(defn- notify-w [this old new] +(defn- notify-w [^clj this old new] (let [w (.-watchesArr this) a (if (nil? w) ;; Copy watches to array for speed @@ -188,7 +188,7 @@ (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) m (if (nil? m) {} m) r (m k nil)] @@ -222,7 +222,7 @@ (cached-reaction #(apply f args) f args this nil))) IEquiv - (-equiv [_ other] + (-equiv [_ ^clj other] (and (instance? Track other) (= f (.-f other)) (= args (.-args other)))) @@ -259,7 +259,7 @@ IReactiveAtom IEquiv - (-equiv [_ other] + (-equiv [_ ^clj other] (and (instance? RCursor other) (= path (.-path other)) (= ratom (.-ratom other)))) @@ -316,7 +316,7 @@ (-hash [_] (hash [ratom path]))) (defn cursor - [src path] + [^clj src path] (assert (or (satisfies? IReactiveAtom src) (and (ifn? src) (not (vector? src)))) @@ -347,7 +347,7 @@ (defprotocol IRunnable (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)) ;; Fields of a Reaction javascript object @@ -578,7 +578,7 @@ (-swap! [a f x y more] (-reset! a (apply f state x y more))) IEquiv - (-equiv [_ other] + (-equiv [_ ^clj other] (and (instance? Wrapper other) ;; If either of the wrappers have changed, equality ;; cannot be relied on. diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 2d36802..cf82b31 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -1318,7 +1318,7 @@ :get-derived-state-from-error (fn [error] #js {:hasError true}) :component-did-catch (fn [this e info]) - :render (fn [this] + :render (fn [^js/React.Component this] (r/as-element (if (.-hasError (.-state this)) [:p "Error"] (into [:<>] (r/children this)))))})