我可以将我的应用程序的内容(试剂成分)存储在重新构建的数据库中吗?

Can i store my app's content (reagent components) in the re-frame db?

这是我的应用程序的结构:

(reg-event-db
  :app-surface-add-layer!
  (fn [db [_ layer-content & [layer-params]]]
      (assoc db :app-surface-layers
             (conj (:app-surface-layers db)
                   {:layer-content layer-content
                    :layer-params layer-params}))))

(reg-sub
  :app-surface-get-layers
  (fn [db _]
      (:app-surface-layers db)))

(defn x-app []
  (let [app-surface-layers (subscribe [:app-surface-get-layers])]
    (fn []
      [:div#app
       [:div#app-topbar "Menu-1, Menu-2, etc."]
       [:div#app-sidebar "Menu-3, Menu-4, etc."]
       [:div#app-surface
        (reduce
          (fn [app-surface layer-data]
              (conj app-surface
                    [(:layer-content layer-data) (:layer-params layer-data)]))
          [:div#app-surface-layers]
          @app-surface-layers)]])))

(defn calendar [params]
  [:div#calendar
   "Calendar"])

; Put the calendar component to the re-frame db
(dispatch [:app-surface-add-layer! #'calendar ["Param-1"]])

我的问题是,我可以将应用程序的内容组件(如示例中的日历)存储在重新构建的数据库中吗? 您如何看待该解决方案的性能?

可以吗?绝对的,到头来都是vector而已,肯定不会影响性能。可读性有点粗糙,我认为有一个 case 或类似的东西会更清楚,以便在尝试阅读代码时更容易分辨 calendar 将在哪些情况下呈现与不同的组件,但这在很大程度上取决于您所做工作的具体情况。