1

你怎么看?哪种解决方案的性能效率更高?

A) 订阅子组件中的 re-frame db atom

B)将该原子作为参数传递给子组件。

以下是 A 的示例:

(defn- sub-1 [] (let [state (r/subscribe [:totoro])] (fn []))
(defn- sub-2 [] (let [state (r/subscribe [:totoro])] (fn []))
(defn- sub-3 [] (let [state (r/subscribe [:totoro])] (fn []))

(defn strawberry []
  [sub-1]
  [sub-2]
  [sub-3])

B 示例:

(defn- sub-1 [state] (fn [] @state))
(defn- sub-2 [state] (fn [] @state))
(defn- sub-3 [state] (fn [] @state))

(defn strawberry []
  (let [state (r/subscribe [:totoro])]
    (fn []
      [sub-1 state]
      [sub-2 state]
      [sub-3 state])))

B/2 的示例:

(defn- sub-1 [state] (fn [] state))
(defn- sub-2 [state] (fn [] state))
(defn- sub-3 [state] (fn [] state))

(defn strawberry []
  (let [state (r/subscribe [:totoro])]
    (fn []
      [sub-1 @state]
      [sub-2 @state]
      [sub-3 @state])))
4

0 回答 0