我当前的项目中有很多 React 组件。如果我决定在 Om 中编写下一个项目,是否可以重用这些组件?
问问题
515 次
1 回答
1
对的,这是可能的。我创建了一个有四个实例的日期组件。一个用于选择日,另一个用于选择周。
所以,当我创建它们时,我传入一个地图来配置它们:
(om/build common/column-input-date {:component-id :selected-daily-date})
(om/build common/column-input-date {:component-id :selected-weekly-date})
(om/build common/column-input-date {:component-id :selected-monthly-date})
(om/build common/column-input-date {:component-id :selected-jobs-date})
然后在组件中:
(defn column-input-date [data owner]
"column input date"
(reify
om/IInitState
(init-state [_]
{:e-map {:display (:display data)
:component-id (:component-id data)}})
om/IDidMount
除此之外,页面,一切都是组件,所以我有大约 20 个组件。我的通过 core.async 进行通信并从 ref-cursors 获取数据。我尝试将数据向下传递到组件树,并确定这是过度耦合的。
于 2015-02-25T22:10:22.987 回答