Commits

Karsten Schmidt committed aa431dc

renaming get-inputs into get-ports, reusing get-node in aliasnode macro

Comments (0)

Files changed (1)

src/estuary/core.clj

             port (:port t)]
         (send a func port value)))))
 
-(defn get-inputs
-  "Filters the given node map and returns a collection of values for keys with the prefix \":in\"."
-  [state]
-  (map (fn [v] (val v)) (filter #(.startsWith (name (key %)) "in") state)))
+(defn get-ports
+  "Filters the given node map and returns a collection of values for keys with the prefix (default \":in\")."
+  ([state] (get-ports state "in"))
+  ([state prefix]
+  (map (fn [v] (val v)) (filter #(.startsWith (name (key %)) prefix) state))))
 
 (defn set-and-accumulate
   "Handler function for an accumulator node with multiple :in terminals (:in0, :in1 etc.)
 of all existing input keys before propagating it to all targets."
   [state id value]
   (let [tmp (assoc state id value)
-        newstate (assoc tmp :value (reduce + (get-inputs tmp)))]
+        newstate (assoc tmp :value (reduce + (get-ports tmp)))]
     (dispatch (:targets newstate) (:value newstate))
     newstate))
 
           targets (filter #(not (and (= (:id %) tid) (= (:port %) port))) (:targets @src))]
       (send src assoc :targets targets) (await src))))
 
-
 (defmacro defgraph
   "Creates a new atom based map container for nodes and assigns it to the given variable."
   [id]
 (defmacro aliasnode
   "Assigns the graph node with the given UUID to a new variable. Useful for working with deserialized graphs."
   [graph id uuid]
-  `(def ~id (get (:nodes @~graph) ~uuid)))
+  `(def ~id (get-node ~graph ~uuid)))
 
 (defn serialize-graph
   "Serializes the given graph to a JSON string."