clojurescript - 手动观看重帧订阅
问题描述
给定一个具有值的重新构建数据库:score
:
(def my-db {:score 0})
(re-frame.core/reg-sub ::score (fn [db] (:score db)))
(re-frame.core/reg-event-db
::initialize-db
(fn [_ _] my-db))
(re-frame.core/reg-event-db
::set-score
(fn [db [_ score]]
(assoc db :score score)))
我希望我应该能够订阅 ::score 并添加一个观察者
> (def score-atom (re-frame.core/subscribe [::score]))
> (add-watch
score-atom
:whatever
(fn [_ _ _ _] (prn "here!")))
然后我应该能够触发更新:
> (re-frame.core/dispatch [::set-score 2])
nil
> @score-atom
"here!"
2
>
与正常的 atom 行为相反,在完成外部 deref 之前,更新不会到达手表。
显然我可以用试剂应用程序包裹手表,但感觉很重。如何让手表立即触发?我宁愿不要在每次发送调度时手动取消订阅。
解决方案
如果我跑步,事情似乎会有所进展(reagent.core/flush)
。
推荐阅读
- vue.js - Vue在更改路由时重新创建父组件
- python - Alpha_vanatage 模块在 PC(Windows)的 cmd 提示符下工作,但在 jupyter notebook 中不工作
- json - 如何根据第二个 JSON 对象的值使 JSON 对象的属性成为必需?
- javascript - 在单击复选框时显示按钮文本
- angularjs - 在控制器之间传递数据时出错
- c# - 在 Swagger UI 中显示 HTTP 请求持续时间
- deep-learning - 如何使用pytorch裁剪图像区域外的特征?
- javascript - 我无法过滤或搜索
- c++ - 如何计算排列的数量?
- bash - tsp 无法运行 bash 命令