Skip to content

Commit

Permalink
fix: selector could cause circular dependency error
Browse files Browse the repository at this point in the history
  • Loading branch information
armed committed Jun 10, 2022
1 parent e15dd90 commit 663bd59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
29 changes: 20 additions & 9 deletions src/k16/gx/beta/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,26 @@
(with-err-ctx {:error-type :deps-sort :signal-key signal-key}
(try
(if-let [signal-config (get-in context [:signals signal-key])]
(let [deps-from (or (:deps-from signal-config)
signal-key)
graph-deps (->> deps-from
(graph-dependencies graph)
(map (fn [[k deps :as signal-deps]]
(if (contains? priority-selector k)
signal-deps
[k (into deps priority-selector)])))
(into {}))
(let [deps-from (or (:deps-from signal-config) signal-key)
selector-deps (reduce (fn [acc k]
(->> [k deps-from :gx/deps]
(get-in graph)
(set)
(assoc acc k)))
{} priority-selector)
graph-deps
(->> deps-from
(graph-dependencies graph)
(map (fn [[k deps :as signal-deps]]
(let [node-selector
(->> selector-deps
(filter (fn [[_ d]] (not (contains? d k))))
(map first)
(set))]
(if (contains? node-selector k)
signal-deps
[k (into deps node-selector)]))))
(into {}))
sorted-raw (impl/sccs graph-deps)]
(when-let [errors (->> sorted-raw
(impl/dependency-errors graph-deps)
Expand Down
7 changes: 5 additions & 2 deletions test/k16/gx/beta/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,10 @@

(deftest signal-selector-test
(let [flow (atom [])
graph {:logger {:gx/component 'k16.gx.beta.core-test/logger-component
:gx/props {:flow flow}}
graph {:logger-config {:foo "bar"}
:logger {:gx/component 'k16.gx.beta.core-test/logger-component
:gx/props {:flow flow
:config '(gx/ref :logger-config)}}
:options {:port 8080}
:db {:gx/component 'k16.gx.beta.core-test/db-component
:gx/props {:flow flow}}
Expand All @@ -475,6 +477,7 @@
:flow flow}}}
norm (gx/normalize {:graph graph})
gx-started (gx/signal norm :gx/start #{:logger})]
(is (= nil (:failures norm)))
#?@(:clj [@gx-started
(is (= [:logger :db :server] @flow))
(reset! flow [])
Expand Down

1 comment on commit 663bd59

@vercel
Copy link

@vercel vercel bot commented on 663bd59 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gx – ./

gx-kepler16.vercel.app
gx-git-master-kepler16.vercel.app
gx.kepler16.com

Please sign in to comment.