0

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

(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"]])

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

4

1 回答 1

0

你能?当然,最终都只是向量,它肯定不会干扰性能。可读性有点粗糙,我认为有一个case或类似的东西会更清楚,以便在尝试阅读代码时更容易区分在哪些情况下calendar将呈现与不同的组件,但其中很多将取决于关于你在做什么的细节。

于 2019-12-31T05:38:22.057 回答