This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-13
Channels
- # adventofcode (35)
- # announcements (2)
- # arachne (1)
- # beginners (71)
- # chestnut (2)
- # cider (100)
- # cljdoc (17)
- # cljs-dev (17)
- # cljsjs (2)
- # cljsrn (2)
- # clojure (53)
- # clojure-austin (2)
- # clojure-europe (1)
- # clojure-finland (2)
- # clojure-italy (3)
- # clojure-nl (7)
- # clojure-russia (56)
- # clojure-spec (56)
- # clojure-uk (35)
- # clojurescript (58)
- # community-development (14)
- # core-async (9)
- # cursive (22)
- # data-science (5)
- # datomic (14)
- # duct (5)
- # emacs (2)
- # expound (4)
- # figwheel-main (6)
- # fulcro (23)
- # kaocha (8)
- # lumo (7)
- # off-topic (10)
- # pathom (6)
- # re-frame (17)
- # reitit (31)
- # ring (3)
- # rum (1)
- # shadow-cljs (45)
- # spacemacs (10)
- # sql (12)
- # testing (9)
- # tools-deps (130)
I was playing around with the idea of checking the spec of the db in my small multipage SPA and I came up with something like this:
(defn ->interceptor
[page db-spec]
(rf/->interceptor
:id :validate
:after (fn [context]
(let [local-db (-> context :effects :db page)]
(if (s/valid? db-spec local-db)
context
(throw (ex-info (str "spec check failed: " (s/explain-str db-spec local-db)) {})))))))
(defn ->safe-event-db
[page db-spec]
(fn [id handler]
(rf/reg-event-db
id
[(->interceptor page db-spec)]
handler)))
which can then be used like
(def safe-event-db (common/->safe-event-db page ::db))
(safe-event-db ::name
(setter [:player :name]))
seems to work well enough, but is this is as good way to do it ?Can I use the :dispatch
effect from other effects? I have a generic event that makes http-calls, and I'd like to add an effect that dispatches it.
Right now my options are to either call (dispatch)
from the effect directly, or turn the effect into another event. No preference either way really
@teemu.kaukoranta sounds like you might want to take a look at interceptors https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md
Reading your message again and I’m not sure anymore what you’re trying to achieve. 😅 So you would like to have an effect that dispatches an event that would be executed by your event-handler? :dispatch
and :dispatch-n
effects are meant exactly for that. But I guess you wanted something more elaborate?
My first attempt was just to use :dispatch
from my event, but I felt like it didn't work. The error could have been elsewhere though
I'll try again
@teemu.kaukoranta Sure you can. Just add in your map the key dispatch
like this:
{:db db
:dispatch [:make-http-call params]}
or if you want to dispatch multiple events in one go you can use :dispatch-n
like this:
{:db db
:dispatch-n [[:make-http-call params]
[:do-something-else params]]}
My first attempt was just to use :dispatch
from my event, but I felt like it didn't work. The error could have been elsewhere though
Nope, when I try to use the :dispatch
effect from my effect, it doesn't seem to fire. Basically I'm trying to build a event->effect->event->...
chain. I could be heading into the wrong direction, but this feels like a solid idea for this case 😅
I think I'm just going to turn my effect into another event. All it does is :dispatch
, but whatever
small docs PR about the namespaced keywords https://github.com/Day8/re-frame/pull/528
Andrea there’s a typo https://github.com/Day8/re-frame/pull/528/files#diff-6cdbf45b44314b03d02cc796aca036d7R90 Also I vaguely remember that using dots in keywords is discouraged (?) Not sure exactly for what reason
ah thanks @U0G75ARHC, I fixed it
and well where am I using dots in keywords?
if you mean
:project.panel.handlers/set-x
that's just the other way to refer to a namespaced keyword