Skip to content

Commit

Permalink
refactor: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
armed committed Jul 1, 2022
1 parent 4caeae5 commit b195c97
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/k16/gx/beta/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -363,26 +363,30 @@
(flatten)
(conj node-key))))

(defn- create-partial-selector
[gx-map signal-key selector]
(some->>
(seq selector)
(map #(selector-with-deps gx-map signal-key %))
(flatten)
(set)))

(defn signal
"Send signal to the graph or to its subset if selectors are passed.
Selectors is a set of top level graph keys, signal will be executed on
selectors and its dependencies according to signal ordering."
([gx-map signal-key]
(signal gx-map signal-key nil))
([gx-map signal-key selector]
(let [gx-map (normalize (dissoc gx-map :failures))
partial-selector (some->> selector
(seq)
(map #(selector-with-deps gx-map signal-key %))
(flatten)
(set))
[error sorted] (topo-sort gx-map signal-key)
gx-map (if error
(update gx-map :failures conj error)
gx-map)]
(if (seq (:failures gx-map))
(p/resolved gx-map)
(p/loop [gxm gx-map
(let [normalized (normalize (dissoc gx-map :failures))
partial-selector (create-partial-selector gx-map signal-key selector)
[error sorted] (topo-sort normalized signal-key)
validated (if error
(update normalized :failures conj error)
normalized)]
(if (seq (:failures validated))
(p/resolved validated)
(p/loop [gxm validated
sorted sorted]
(cond
(seq sorted)
Expand Down

0 comments on commit b195c97

Please sign in to comment.