   "Given the accumulated set of seen events and the set of tasks already started,
   return the list of tasks which should now be started.
   In effect, given the list of events seen has changed, what is the consequence."
-  [rules now-seen-events started-tasks]
-  (->> (remove (comp started-tasks :id) rules)   ;; we identify tasks by `:dispatch`
+  [rules now-seen-events already-started-tasks]
+  (->> (remove (comp already-started-tasks :id) rules)
        (filterv (fn [task] ((:when task) (:events task) now-seen-events)))))
+
 
 (defn massage-rules
   "Massage the supplied rules as follows:

                      (fn [db] (get-in db db-path))
                      (fn [_]  @local-store))

        rules  (massage-rules id rules)
        all-events  (apply set/union (map :events rules))]       ;; all of the events refered to in the rules

    ;; return an event handler which will manage the flow
    ;; This event handler will receive 3 kinds of events

                {:db       (set-state db new-seen-events new-started-tasks)
                 :dispatch (concat (map :dispatch ready-tasks))}))))


(re-frame.core/def-fx
  :aync-flow
  (fn [{:as flow :keys [id]}]
    (re-frame.core/def-event-fx
      (or id default-id)                                 ;; add debug middleware???  XXX
      (make-flow-event-handler flow))
    (re-frame.core/dispatch [id :steup])))

