diff --git a/src/re_frame/core.cljs b/src/re_frame/core.cljs index f59615e..ad0e19e 100644 --- a/src/re_frame/core.cljs +++ b/src/re_frame/core.cljs @@ -2,14 +2,15 @@ (:require [re-frame.handlers :as handlers] [re-frame.subs :as subs] + [re-frame.router :as router] [re-frame.middleware :as middleware])) ;; -- API ------- (def register-handler handlers/register) -(def dispatch handlers/dispatch) -(def dispatch-sync handlers/dispatch-sync) +(def dispatch router/dispatch) +(def dispatch-sync router/dispatch-sync) (def register-sub subs/register) (def subscribe subs/subscribe) @@ -22,6 +23,7 @@ (def path middleware/path) (def validate middleware/validate) (def trim-v middleware/trim-v) +(def after middleware/after) ; (def log-events middleware/log-events) diff --git a/src/re_frame/handlers.cljs b/src/re_frame/handlers.cljs index 3146308..a289e5e 100644 --- a/src/re_frame/handlers.cljs +++ b/src/re_frame/handlers.cljs @@ -1,20 +1,14 @@ (ns re-frame.handlers - (:refer-clojure :exclude [flush]) - (:require-macros [cljs.core.async.macros :refer [go-loop go]]) - (:require [reagent.core :refer [flush]] - [re-frame.db :refer [app-db]] - ; [re-frame.middleware :refer [noop]] - [re-frame.utils :refer [first-in-vector warn]] - [cljs.core.async :refer [chan put! fn (atom {})) + (defn lookup-handler [event-id] (get @id->fn event-id)) + (defn register "register a handler for an event" ([event-id handler-fn] @@ -46,17 +41,11 @@ (swap! id->fn assoc event-id handler-fn)) ([event-id middleware handler-fn] - (let [mid-ware (comp-middleware middleware) - hander-fn (mid-ware handler-fn)] + (let [mid-ware (comp-middleware middleware) ;; compose the middleware + hander-fn (mid-ware handler-fn)] ;; wrap the handler in the middleware (register event-id hander-fn)))) -;; -- The Event Conveyor Belt -------------------------------------------------------------------- -;; -;; Moves events from "dispatch" to the router loop. -;; Allows for the aysnc handling of events. -;; -(def ^:private event-chan (chan)) ;; TODO: set buffer size? ;; -- lookup and call ----------------------------------------------------------------------------- @@ -76,50 +65,3 @@ (warn "re-frame: no event handler registered for: \"" event-id "\". Ignoring.") ;; TODO: make exception (handler-fn app-db event-v)))) - -;; -- router loop --------------------------------------------------------------------------------- -;; -;; In a perpretual loop, read events from the dispatch channel, and route them -;; to the right handler. -;; -;; Because handlers occupy the CPU, before each event is handled, hand -;; back control to the browser, via a (