re-frame icon indicating copy to clipboard operation
re-frame copied to clipboard

Event handler documentation

Open gacelita opened this issue 7 years ago • 4 comments

At the moment, re-frame does not give users a way of adding docstrings to event handlers. I open this issue to discuss this possibility. Adding specs could be useful too (I'm fond of data specs)

Quick proof of concept for adding documentation, which extends reg-event-fx (ignores interceptors though)

(defonce ^:private extended-event-handler-data (atom {}))

(defn reg-event-fx
  ([kw f]
   (rf/reg-event-fx kw f))
  ([kw options f]
   (swap! extended-event-handler-data assoc kw options)
   (rf/reg-event-fx kw f)))

(defn event-handler-doc [kw]
  (:doc (get @extended-event-handler-data kw)))

(reg-event-fx
 ::categories.list
 {:doc "Lists categories indeed"}
 (fn [_ _]
   {:dispatch ["..."]}))

;;
;;

(event-handler-doc ::categories.list)
=> "Lists categories indeed"

gacelita avatar Mar 08 '18 22:03 gacelita

Thanks. I'm working on a plan. More soon.

mike-thompson-day8 avatar Mar 31 '18 02:03 mike-thompson-day8

Hello @mike-thompson-day8 I'd like to contribute with this project by delivering a free logo proposal if thats something you're interested on, let me know, Greetings!

LuigiBaute avatar May 08 '18 14:05 LuigiBaute

Why does a string after the keyword not work here, like it does for function definitions?

ghost avatar Nov 22 '18 10:11 ghost

Until some kind of docstringability is added to re-frame, what would the suggested best practice be for clarifying quirky events? Comments above the reg-event-fx?

celwell avatar Aug 08 '19 00:08 celwell

Until some kind of docstringability is added to re-frame, what would the suggested best practice be for clarifying quirky events? Comments above the reg-event-fx?

Either that, or extracting the complex functionality (or all the functionality) to a function, and document the function

gacelita avatar Aug 08 '19 06:08 gacelita