You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何re-frame订阅命令仅在特定浏览器地址生效?

问题:re-frame订阅结果受浏览器地址影响

技术栈与项目环境

  • 使用Clojure、ClojureScript、lein、shadow-cljs、Emacs+CIDER开发动态Web应用
  • 启动方式:Emacs中执行cider-jack-in-cljs,选择shadow-cljs、shadow作为REPL类型,app作为构建选项,项目正常运行,可通过localhost:3005查看UI变更

问题现象

在REPL中执行@(re-frame.core/subscribe [:the-selections])时,仅当浏览器处于特定页面地址时返回有效数据,认证状态不影响此现象:

  • 在地址http://localhost:3005/link/random-numbers-asidadbsadkfbajhksdbf9283492374下执行命令,返回:
    cljs.user> @(re-frame.core/subscribe [:the-selections])
    
    {:firm "cb08795f-378b-4eb0-9404-ad83b83a8474",
     :active-client "Random-client",
     :active-atb "c6193c35-bf91-4711-8523-d905bd7f0a03"}
    
  • 切换到有效路径http://localhost:3005/another-path时,执行相同命令返回:
    cljs.user> @(re-frame.core/subscribe [:the-selections])
    nil
    

首页或认证完成后执行该命令同样返回nil,仅特定页面地址下可用。

相关订阅定义

附上:the-selections的定义:

(rf/reg-sub
  :the-selections

  ;; Only returns something if all :firm, :active-client, and
  ;; :active-atb are present. :raw-selections defined in
  ;; selections.cljs omits validation if (rarely) needed.  selections
  ;; are only stored locally in re-frame's app-db, not in firebase,
  ;; like :the-client and :the-atb. Minor selections components which
  ;; are not part of the validation are :active-account and :active-je

  (fn [_q _d]
    (rf/subscribe [:raw-selections]))
  (fn [selections _q]
    (tc-selections/valid-selections selections)))

疑问

re-frame的订阅不是数据库的接口吗?根据re-frame文档:

当视图函数使用(subscribe [:something :needed])这样的订阅时,会创建服务该订阅所需的节点子图,必要的子图会从视图函数反向延伸至app-db。

既然如此,为何浏览器地址栏会影响REPL中订阅命令的执行结果?

内容的提问来源于stack exchange,提问作者Pedro Delfino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 03:35:22