This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-03
Channels
- # adventofcode (1)
- # beginners (76)
- # boot (88)
- # cider (63)
- # clojure (357)
- # clojure-austin (2)
- # clojure-berlin (8)
- # clojure-brasil (8)
- # clojure-nl (1)
- # clojure-russia (22)
- # clojure-spec (17)
- # clojure-uk (47)
- # clojurescript (67)
- # cursive (45)
- # datascript (3)
- # datomic (45)
- # dirac (7)
- # emacs (3)
- # funcool (2)
- # hoplon (26)
- # jobs (2)
- # jobs-discuss (11)
- # luminus (6)
- # off-topic (243)
- # om (40)
- # om-next (7)
- # onyx (23)
- # overtone (1)
- # portland-or (2)
- # protorepl (11)
- # re-frame (55)
- # reagent (58)
- # rum (12)
- # sql (4)
- # test-check (12)
- # untangled (25)
Nicely done.
Hey I've been having trouble converting pre 0.8.0 middleware handlers to interceptors
is there any doc or guide to definitively change the old style middleware fn's to interceptors?
@mattsfrey What I'd do: 1. Understand Interceptors by reading all the 'Event Handlers" section of the docs: https://github.com/Day8/re-frame/blob/master/docs/README.md 2. Look at the way the standard middleware was converted to interceptors (eg: debug and trim, etc) 3. Realize there is no mechanical way to do the conversion. It has to be done by hand. But, we should only be talking 10 lines of code per middleware/interceptor.
Regarding point 2 above ... pick a particular interceptor, like enrich
or debug
and compare before and after ....
after: https://github.com/Day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc before: https://github.com/Day8/re-frame/blob/f0124ecf4be5c8e978a149de73d8a1fb6e443eb0/src/re_frame/middleware.cljs
yeah I ended up reading the docs pretty throughly, had to rearrange some things due to the before/after mechanism
i.e. printing logs of changes I print the event name on the before and the diff on the after (the event name gets stripped from the trim-v interceptor and is thus unavailable on the after flow)
(def debug
(re-frame/->interceptor
:id :debug
:before (fn [context]
(let [{:keys [event]} (:coeffects context)]
(log/group "Event: " (first event))
(log/log event))
context)
:after (fn [context]
(let [{:keys [db]} (:coeffects context)
new-db (-> context :effects :db)
diff (data/diff db new-db)]
(log/debug "Before: " (first diff))
(log/debug "After : " (second diff))
(log/group-end)
context))))
Seem entirely reasonable. Be aware though that :effects
might not have a :db
(reg-event-fx
:some-id
(fn [cofx event]
{:http {:url "http://example.com/blah"}}))
`
That event handler only has a :http
effect
No :db
effect
ohhh ok, well this code base goes back about 7 months now, so we actually only have the old school pure db handlers
https://github.com/Day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L17-L51
See the check on line 41
does skipping the log if there was no change improve performance at all or do you know?
debug
should only be used in developement, never production
So it isn't about performance
It is about quality of logs (in js/console)
lol, wow. this fn has color coded expanding pretty print stuff as well... just mad I spent like 2 hours figuring out how to reproduce a ghetto version of this myself.. good learning experience though I suppose. Thanks for the tips!
@mattsfrey In 0.9.1, the trim-v
interceptor puts the event name back 🙂
Yes, was requested. Causing a problem?
@mattsfrey Said earlier that it strips the event name: https://clojurians.slack.com/archives/re-frame/p1483471941003099
Got it. Thanks for the clarification
=================================
Tip of the day
Learn to use enrich
for validation and detecting warning/error states:
https://github.com/Day8/re-frame/blob/master/src/re_frame/std_interceptors.cljc#L195-L227
=================================
left most?
or right most?
(def middleware [(when ^boolean js/goog.DEBUG re-frame/debug)
dispatch-once-support
re-frame/trim-v])
Should be fine
As @curlyfry pointed out above, I think any issues were fixed in 0.9,1
Ie. event is restored to its full glory now, on the backwards sweep
Say, I'm not seeing the 0.8.0 syntax sugar :<- [:some :subscription]
stuff for (reg-sub)
in the docs any more. Am I just missing it, or is it deprecated?
(I actually prefer the two-fn form of reg-sub, personally, but we've got some old code that uses the :<-
form, not sure if I should try to refactor it out while I'm in there messing around)
Nothing has changed. Still a part of the docs via the annotated todomvc source:
Oh, gotcha. Ok, thanks @mikethompson