Fork me on GitHub
#re-frame
<
2016-07-13
>
escherize00:07:21

Are there plans for re-frame 8 to be compatible with pre-spec versions of clojure?

danielcompton00:07:26

Don’t think there’s anything spec specific in re-frame 8

escherize00:07:52

There is spec specific code in re-frame 8, though.

escherize00:07:10

line 3 of re-frame.subs has it

danielcompton00:07:09

shows how much I know 🙂

richiardiandrea00:07:33

In the draft doc it says "not yet", also, I asked in the issue related to v8 about CLJS-1701 and Mike said it is not in yet

richiardiandrea00:07:24

By the way it bothers me slightly that the name will change from register-handler to def-event. In my head I am not defining an event but indeed an event handler. Am I macaroni ? 😃😃😃

escherize01:07:26

We will run sanity checks on the dispatch and subscription functions in clojure using cljc

michael.heuberger01:07:20

@escherize: that’s a good idea - can you share an example of sanity checking dispatch/sub here?

escherize01:07:42

I've been working on it but havn't rolled middleware into the equation yet.

escherize01:07:24

(ns rokt-frame.re-frame-cljc)

(def warn
  #?(:clj (fn warn [& xs] (println "[clj] Warning: " xs)))
  #?(:cljs re-frame.core/warn))

#?(:clj (def reaction atom))
#?(:clj (defonce app-db (atom {})))
#?(:clj (defonce id->fn (atom {})))
#?(:clj (defonce key->fn (atom {})))

#?(:clj (defn register-handler [kw & mw+fn]
          (let [mw (drop-last mw+fn) ;; ignore this.
                db-fxn (last mw+fn)]
            (when (get @id->fn kw)
              (warn "Handler " kw " is being overwritten."))
            (swap! id->fn assoc kw db-fxn)
            (str "assoc'd " kw " to id->fn"))))

#?(:clj (defn dispatch [[dispatch-kw & args :as dispatch-vector]]
          (let [db-fxn (get @id->fn dispatch-kw)
                _ (assert db-fxn (str "db-fxn for kw: "
                                      dispatch-kw
                                      " does not exist!!"))]
            (swap! app-db #((partial db-fxn %) dispatch-vector)))))

#?(:clj (defn register-sub [kw sub-fn]
          (when (get @key->fn kw)
            (println "Subscription " kw " is being overwritten."))
          (swap! key->fn assoc kw sub-fn)
          (str "assoc'd " kw " to key->fn")))

#?(:clj (defn subscribe [[sub-kw]]
          (let [sub-fn (get @key->fn sub-kw)]
            (sub-fn app-db))))

escherize01:07:59

that's half baked but it can be used like:

(do (dispatch [:initialize-db])
      (dispatch [:update-name "George"])
      (= @app-db
         {:name "George", :order :shuffle}))

michael.heuberger01:07:51

mmmh, but dispatch doesn’t modify db immediately

michael.heuberger01:07:06

unless it is dispatch-sync

escherize01:07:13

true, it's not a perfect representation

escherize01:07:26

of what happens in re-frame

escherize01:07:02

but it's enough to test sequential app-db interactions (without javascript)

mikethompson01:07:19

@escherize: @danielcompton I'll take that reference to spec out of the requires

escherize01:07:40

That is necessary but it might not be sufficient to enable our use of re-frame with pre-spec clojure.

mikethompson01:07:22

@escherize: What else might be a problem?

mikethompson01:07:12

@richiardiandrea: i know what you mean about def-event vs register-event

mikethompson01:07:08

I do feel conflicted. I liked def because it was short. And because I wanted to make a clear break with previous naming, to avoid any confusion.

sam.roberton01:07:43

The reference to spec is there because register-pure uses clojure.spec/conform to parse its arguments. It might not be so easy just to take out of the requires 🙂

mikethompson01:07:04

Ahh. Now I remember.

mikethompson01:07:12

We'll redo that so we remove the dependency

mikethompson01:07:39

Until such time as spec can be DCE it will liekly be a problem for people

sam.roberton01:07:30

To answer @mikethompson's "what else" question to @escherize, the other discussions we'd had internally about ability to use re-frame 8 were more about the update to reagent and react dependencies, which I don't think are actual problems, just things we need to do our due diligence on.

michael.heuberger01:07:54

do you guys know if it’s okay to dispatch multiple events in dispatch-sync? something like

(dispatch-sync [:eventA (:data 123)
                             :eventB (:data 123)])

mikethompson01:07:18

@sam.roberton: Right. Reagent shouldn't be a problem. But we found that React 15 was stricter. We got warnings from it when we upgraded.

escherize01:07:20

I dont think that will work, michael.heuberger.

sam.roberton01:07:53

I haven't had problems with it in my side project, so I don't anticipate any for the day job either. We just need to check 🙂

escherize01:07:04

in [:eventA (:data 123) :eventB (:data 123)], :eventB and (:data 123) will be assumed to be an arg for :eventA.

mikethompson01:07:16

@michael.heuberger: won't work Do this: (map dispatch (list [:event1] [:event2]))

mikethompson01:07:06

Also dispatch-sync should be avoided unless you know what you are doing.

michael.heuberger01:07:33

good idea with map … well, using dispatch-sync here only during app start up procedure

mikethompson01:07:00

Fair enough, the one use case for dispatch-sync is indeed initiaisation

escherize01:07:00

doseq would be better, as map is lazy

mikethompson01:07:10

Oh, yeah. Ture

escherize01:07:44

(doseq [event [[:eventA 123] [:eventB 234]]] 
  (dispatch-sync event))

escherize01:07:45

or just write it twice (probably what i would do unelss there are a variable amount of events)

richiardiandrea04:07:55

@mikethompson: what about def-handler ? 😉

mikethompson04:07:22

The trouble with "handler" is that there are three kinds: - event handlers - subscription handlers - effects handlers (new)

mikethompson04:07:19

@richiardiandrea: ^^ which is why I went for event over handler. I'm happy with that part. But it is just what happens in front of that. Should it be: - def-event (current proposal) - register-event - reg-event - other?

mikethompson04:07:17

Remember that this decision then flows into equivalent naming for subs and effects too.

escherize06:07:28

guys stop bikeshedding. 😛

richiardiandrea16:07:48

@mikethompson: just to continue to do philosophy, I was picturing the register-subs not as a handler but as creator of a subscription (object, but don't tell anyone), which is then returned. About effects: def-effect, because I picture it as executing a side effect. I picture a def-event more like a (def user-logged [:user-logged ...]). Not trying to convince you, just trying to speak my brains out ☺️