我有以下重构代码:
;;sub
(reg-sub
:active-panel
(fn [db]
(:active-panel db)))
;;event
(reg-event-db
:active-panel
(fn [db [_ new-panel]]
(assoc db :active-panel new-panel)
))
(defn another []
(fn []
[:div
[:p "another"]
]
)
)
(defn main []
(fn []
[:div
[button {:label "Button"
:on-click #(dispatch [:active-panel :another])
}]
]
))
(defmulti panels identity)
(defmethod panels :main [] [main])
(defmethod panels :another [] [another])
(defmethod panels nil [] [:p "nil"])
(defn main-panel []
(let [active-panel (subscribe [:active-panel])]
(fn []
(panels @active-panel))))
基本上,主(默认)面板中有一个按钮,单击该按钮时应该会到达 :another 面板,但它会在“nil”面板和 :another 面板之间闪烁。我究竟做错了什么?