1. Karsten Schmidt
  2. clj-estuary


Karsten Schmidt  committed 80c544e

updating trigger function to support node IDs and node collections

  • Participants
  • Parent commits 156fd49
  • Branches default

Comments (0)

Files changed (2)

File project.clj

View file
 (defproject estuary "0.3.0-SNAPSHOT"
-  :description "Easy construction of dataflow graphs using standard Clojure agents."
-  :dependencies [[org.clojure/clojure "1.3.0"]
-                 [clj-json "0.4.3"]]
+  :description "Easy construction of dataflow compute graphs using standard Clojure agents."
+  :dependencies [
+     [org.clojure/clojure "1.3.0"]
+     [clj-json "0.4.3"]
+  ]
   :dev-dependencies [
-	[lein-marginalia "0.6.1"]
-	[lein-eclipse "1.0.0"]
+     [lein-marginalia "0.6.1"]
+     [lein-eclipse "1.0.0"]
-  :main estuary.core)
+  :main estuary.core

File src/estuary/core.clj

View file
               port (:port t)]
           (send a func port value))))))
-(defn trigger
-  "If only the node is specified, triggers the propagation of the node's current
-value to all of its targets.
-If key and value are given, triggers the node's update handler."
-  ([n]
-  (send n (resolve (symbol (:func @n)))))
-  ([n k v]
-    (send n (resolve (symbol (:func @n))) k v)))
 (defn ports
   "Filters the given node map and returns a collection of values for keys matching the
 given regexp (default \"in\\d+\")."
         with-targets (nodes-with-targets graph)]
     (reduce #(disj %1 %2) all with-targets)))
-(defn trigger-emitters
-  [graph]
-  (map #(trigger (node-for-id graph %)) (emitters graph)))
 (defn node-target-tree
   "Constructs a nested vector of all direct & indirect target IDs
   for the given node. The graph MUST be acyclic.
               (conj branch (:id @a) b))))
           [] tlist))))
+(defn trigger
+  "Triggers the update handler of a single node or node collection.
+  Nodes can be given as direct references or IDs. If the latter the
+  parent graph needs to be given as well.
+  For single nodes a key and value can be specified too."
+  ([n]
+    (cond
+      (= (type n) clojure.lang.Agent) (send n (resolve (symbol (:func @n))))
+      (coll? n) (map #(trigger %) n)))
+  ([graph nid]
+    (cond
+      (string? nid) (trigger (node-for-id graph nid))
+      (coll? nid) (map #(trigger (node-for-id graph %)) nid)))
+  ([n k v]
+    (send n (resolve (symbol (:func @n))) k v))
+  ([graph nid k v]
+    (let [n (node-for-id graph nid)]
+      (send n (resolve (symbol (:func @n))) k v))))
 (defn conn!
   "Creates a connection from the given source node to a target node.
 The nodes need to be either supplied as node references or UUIDs.
         (assoc state
                :targets (conj (:targets state)
                               (merge {:agent target :id (:id @target) :port port} custom)))))
-    (await src)
-    (spit "foo.txt" @src))
+    (await src))
   ([g sid tid port custom]
       (conn! (node-for-id g sid) (node-for-id g tid) port custom)))
   ([src target port]
     (let [tid (:id @target)
           targets (filter #(not (and (= (:id %) tid) (= (:port %) port))) (:targets @src))]
-      (send-off src assoc :targets targets) (await src)))
+      (send-off src assoc :targets targets)
+      (await src)))
   ([g sid tid port]
     (let [src (node-for-id g sid)
           targets (filter #(not (and (= (:id %) tid) (= (:port %) port))) (:targets @src))]
-      (send src assoc :targets targets)
+      (send-off src assoc :targets targets)
       (await src))))
 (defmacro defgraph