Skip to content

Commit

Permalink
added help
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Dec 12, 2016
1 parent 0b2a62b commit d82761e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dev/re_frisk/demo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
(assoc db :timer value))) ;; return the new version of db


(reg-event-db
(reg-event-fx
:clock?-db
(fn
;; the first item in the second argument is :timer the second is the
;; new value
[db [_ value]]
(assoc db :clock? value)))
[{db :db} [_ value]]
{:db (assoc db :clock? value)}))
;; -- Subscription Handlers ---------------------------------------------------


Expand Down
23 changes: 20 additions & 3 deletions src/re_frisk/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[re-frisk.data :refer [re-frame-events re-frame-data initialized deb-data]]
[re-frisk.devtool :as d]
[re-frisk.ui :as ui]
[re-frisk.help :as h]
[re-frame.registrar :refer [kind->id->handler]]
[re-frame.core :refer [reg-sub reg-event-db subscribe] :as rfr]))

Expand All @@ -23,16 +24,32 @@
(defn enable-re-frisk! [& params]
(when-not @initialized
(let [prefs (first params)
event (reaction (into {} (map (fn [a] (hash-map (first a) (map #(merge {(:id %) "id"} (when (:before %) {:before "fn"}) (when (:after %) {:after "fn"})) (second a))))
event (reaction (into {} (map (fn [a]
(hash-map (first a)
(let [intc (map #(merge {(:id %1) (cond (and (= %2 0) (= (:id %1) :coeffects)) (:coeffects h/intrcp)
(and (= %2 1) (= (:id %1) :do-fx)) (:do-fx h/intrcp)
(= (:id %1) :db-handler) (:db-handler h/intrcp)
(= (:id %1) :fx-handler) (:fx-handler h/intrcp)
:else "id")}
(when (:before %1) {:before (cond (and (= %2 0) (= (:id %1) :coeffects)) (:coeffects h/intrcp-fn)
(= (:id %1) :db-handler) (:db-handler h/intrcp-fn)
(= (:id %1) :fx-handler) (:fx-handler h/intrcp-fn)
:else "fn")})
(when (:after %1) {:after (cond (and (= %2 1) (= (:id %1) :do-fx)) (:do-fx h/intrcp-fn)
:else "fn")}))
(second a)
(range (count (second a))))]
(hash-map (str (count intc) " interceptors")
intc))))
(filter #(not= (key %) :re-frisk/update-db) @(reaction (:event @kind->id->handler))))))
sub (reaction (into {} (map #(let [k (first %)]
(hash-map k (subscribe [k])))
(filter #(not= (first %) ::db) @(reaction (:sub @kind->id->handler))))))]
(reg-sub ::db (fn [db _] db))
(reset! re-frame-data {:handlers {:event {(count @event) event}
:sub {(count @sub) sub}
:fx (reaction (keys (:fx @kind->id->handler)))
:cofx (reaction (keys (:cofx @kind->id->handler)))}
:fx (reaction (map #(if (% h/fx) {% (% h/fx)} %) (keys (:fx @kind->id->handler))))
:cofx (reaction (map #(if (% h/cofx) {% (% h/cofx)} %) (keys (:cofx @kind->id->handler))))}
:app-db (subscribe [::db])})
(reset! initialized true)
(swap! deb-data assoc :prefs prefs)
Expand Down
19 changes: 19 additions & 0 deletions src/re_frisk/help.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns re-frisk.help)

(def fx {:db "reset! app-db with a new value. Expects a map. / re-frame's internal"
:dispatch "`dispatch` one event. Expects a single vector. / re-frame's internal"
:dispatch-n "`dispatch` more than one event. Expects a list or vector of events. Something for which sequential? returns true. / re-frame's internal"
:deregister-event-handler "Removes a previously registered event handler. Expects either a single id (typically a keyword), or a seq of ids. / re-frame's internal"
:dispatch-later "`dispatch` one or more events after given delays. Expects a collection of maps with two keys: :`ms` and `:dispatch`. / re-frame's internal"})

(def cofx {:db "Adds to coeffects the value in `app-db`, under the key `:db`. / re-frame's internal"})

(def intrcp {:coeffects "An interceptor which injects re-frame :db coeffect. / re-frame's internal"
:do-fx "An interceptor which actions a `context's` (side) `:effects`. For each key in the `:effects` map, call the `effects handler` previously registered using `reg-fx`. / re-frame's internal"
:db-handler "An interceptor which wraps the kind of event handler given to `reg-event-db`. These handlers take two arguments; `db` and `event`, and they return `db`. / re-frame's internal"
:fx-handler "An interceptor which wraps the kind of event handler given to `reg-event-fx`. These handlers take two arguments; `coeffects` and `event`, and they return `effects`. / re-frame's internal"})

(def intrcp-fn {:coeffects "Function which adds to coeffects the value in `app-db`, under the key `:db`. / re-frame's internal"
:do-fx "Function which calls the `effects handler` previously registered using `reg-fx` for each key in the `:effects` map. / re-frame's internal"
:db-handler "Function which calls the handler given to `reg-event-db`. This handler take two arguments; `db` and `event`, and returns `db`. / re-frame's internal"
:fx-handler "Function which calls the handler given to `reg-event-fx`. This handler take two arguments; `coeffects` and `event`, and returns `effects`. / re-frame's internal"})

0 comments on commit d82761e

Please sign in to comment.