 (ns re-frame.fx
-  (:require [re-frame.router :refer [dispatch]]
+  (:require [reagent.ratom  :refer [IReactiveAtom]]
+            [re-frame.router :refer [dispatch]]
             [re-frame.db :refer [app-db]]
             [re-frame.events]
             [re-frame.loggers    :refer [console]]))

  [handler]
  (fn fx-handler
    [app-db event-vec]
    (let [world   {:db @app-db}]
      (->> (handler world event-vec)
           (map (fn [[key val]]

#_(register
  :forward-events
  (let [id->listen-fn (atom {})
        process-one-entry (fn [{:as m :keys [listen events dispatch-to unlisten]}]
                            (let [_  (assert (map? m) (str "re-frame: effects handler for :forward-events expected a map or a list of maps. Got: " m))]   ;; XXX do this better
                              (if  unlisten
                                (do
                                  (re-frame.core/remove-post-event-callback (@id->listen-fn unlisten))
                                  (swap! id->listen-fn dissoc unlisten))
                                (let [post-event-callback-fn  (fn [event-v _]
                                                                (when (events (first event-v))
                                                                  (dispatch (conj dispatch-to event-v))))]
                                  (re-frame.core/add-post-event-callback  post-event-callback-fn)
                                  (swap! id->listen-fn assoc listen post-event-callback-fn)))))]
    (fn [val]
      (cond
        (map? val) (process-one-entry val)
        (list? val) (doall (map process-one-entry val)))     ;; XXX add else
      )))


(register
