Skip to content

Commit

Permalink
Warn when registering a flow causes stale dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Nov 14, 2023
1 parent 62a571f commit 711a584
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/re_frame/flow/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,35 @@
:output (constantly true)
:live? (constantly true)
:live-inputs {}
:init (fn [db path] db)
:init (fn [db path] (assoc-in db path {}))
:cleanup deep-cleanup})

(map :inputs (vals @flows))
(defn warn-stale-dependencies [new-flow]
(doseq [{:keys [id path inputs]} (vals @flows)
:let [bad-output-flows (filter (comp #{path} second) (:inputs new-flow))
bad-input-flows (filter (comp #{(:path new-flow)} second) inputs)]]
(when (some seq [bad-output-flows bad-input-flows])
(console :warn "Warning: while registering the" (:id new-flow) "flow:")
(doseq [[input path] bad-output-flows]
(console :warn "you registered the input" input
"as a db path, but the flow" id
"already outputs to this path:" (str path)
"consider using re-frame.flow/output to reflect this dependency."))
(doseq [_ bad-input-flows]
(console :warn "you registered the output path" (str (:path new-flow) ",")
"but the flow" id
"already inputs from this path."
"Consider changing the inputs of" id
"to reflect this dependency.")))))

(defn reg-flow
([k m] (reg-flow (assoc m :id k)))
([m] (swap! flows assoc
(id m) (with-meta (merge (default (id m)) m)
{::new? true
::ref (r/cursor db/app-db (:path m))}))))
([m]
(warn-stale-dependencies m)
(swap! flows assoc
(id m) (with-meta (merge (default (id m)) m)
{::new? true
::ref (r/cursor db/app-db (:path m))}))))

(defn clear-flow
([]
Expand Down

0 comments on commit 711a584

Please sign in to comment.