Skip to content

Commit

Permalink
feat: signal flow control via :gx/after
Browse files Browse the repository at this point in the history
  • Loading branch information
armed committed Jun 9, 2022
1 parent 9ad2e27 commit a799018
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/k16/gx/beta/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
def? (and (map? signal-def)
(some #{:gx/props :gx/props-fn
:gx/processor :gx/deps
:gx/resolved-props}
:gx/resolved-props :gx/after}
(keys signal-def)))
with-pushed-down-form
(if def?
Expand Down Expand Up @@ -326,7 +326,10 @@
(defn graph-dependencies [graph signal-key]
(->> graph
(map (fn [[k node]]
(let [deps (-> node signal-key :gx/deps)]
(let [deps (-> node
signal-key
:gx/deps
(concat (or (:gx/after node) [])))]
[k (into #{} deps)])))
(into {})))

Expand Down
1 change: 1 addition & 0 deletions src/k16/gx/beta/schema.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
[:gx/props-schema {:optional true} any?]
[:gx/resolved-props-fn {:optional true} [:maybe fn?]]
[:gx/deps {:optional true} coll?]
[:gx/after {:optional true} set?]
[:gx/resolved-props {:optional true} [:maybe any?]]])

(def ?NormalizedNodeDefinition
Expand Down
21 changes: 21 additions & 0 deletions test/k16/gx/beta/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,24 @@
:failures
first
(update :internal-data dissoc :component-schema)))))))

(def server-component
{:gx/start {:gx/processor (fn [_] :http-server)}
:gx/stop {:gx/processor (fn [_] nil)}})

(def logger-component
{:gx/start {:gx/processor (fn [_] :logger)}
:gx/stop {:gx/processor (fn [_] nil)}})

(deftest signal-flow-dependency-test
(let [graph {:logger {:gx/component 'k16.gx.beta.core-test/logger-component}
:options {:port 8080}
:other {:gx/after #{:server}}
:server {:gx/component 'k16.gx.beta.core-test/server-component
:gx/props '(gx/ref :options)
:gx/after #{:logger}}}
norm (gx/normalize {:graph graph})]
(is (= '(:server :other :options :logger)
(second (gx/topo-sort norm :gx/stop))))
(is (= '(:logger :options :other :server)
(second (gx/topo-sort norm :gx/start))))))

1 comment on commit a799018

@vercel
Copy link

@vercel vercel bot commented on a799018 Jun 9, 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.kepler16.com
gx-git-master-kepler16.vercel.app

Please sign in to comment.