This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-29
Channels
- # announcements (35)
- # aws (40)
- # babashka (10)
- # beginners (119)
- # calva (25)
- # cider (13)
- # clj-kondo (15)
- # cljsrn (23)
- # clojure (205)
- # clojure-dev (3)
- # clojure-europe (15)
- # clojure-germany (3)
- # clojure-italy (3)
- # clojure-nl (2)
- # clojure-uk (58)
- # clojurescript (193)
- # community-development (2)
- # conjure (147)
- # core-async (49)
- # cursive (47)
- # datomic (27)
- # duct (1)
- # fulcro (19)
- # graalvm (3)
- # graphql (1)
- # helix (3)
- # hoplon (11)
- # jackdaw (1)
- # joker (1)
- # juxt (5)
- # kaocha (1)
- # keechma (3)
- # lambdaisland (6)
- # local-first-clojure (27)
- # malli (5)
- # off-topic (41)
- # rdf (27)
- # re-frame (7)
- # reagent (15)
- # reitit (5)
- # rum (11)
- # shadow-cljs (157)
- # spacemacs (18)
- # sql (4)
- # xtdb (8)
Hello everyone, I’m working through a basic re-frame example following the intro guide. I have a very simple `dispatch-sync [:initialize]` call and a simple event handler:
(rf/reg-event-db
:initialize
(fn [_ _]
{:message "I'm initialized!"}))
However, I’m getting this error in my console:
core.cljs:3912 re-frame: no :event handler registered for: :initialize
eval @ core.cljs:3912
eval @ core.cljs:3907
eval @ core.cljs:3901
eval @ core.cljs:3895
eval @ core.cljs:3889
eval @ core.cljs:3924
eval @ loggers.cljc:40
eval @ registrar.cljc:31
re_frame$events$handle @ events.cljc:57
re_frame$router$dispatch_sync @ router.cljc:265
alpha_journal$core$main @ core.cljs:24
eval @ shadow.module.main.append.js:4
goog.globalEval @ main.js:836
env.evalLoad @ main.js:2224
(anonymous) @ main.js:2429
This is my core.cljs (entry file):
(ns alpha-journal.core
(:require
[reagent.core :as r]
[reagent.dom :as dom]
[re-frame.core :as rf]
[alpha-journal.views :refer [app]]))
(defn render
[]
(dom/render [app]
(js/document.getElementById "app")))
(defn ^:dev/after-load clear-cache-and-render!
[]
;; The `:dev/after-load` metadata causes this function to be called
;; after shadow-cljs hot-reloads code. We force a UI update by clearing
;; the Reframe subscription cache.
(rf/clear-subscription-cache!)
(render))
(defn main
[]
(rf/dispatch-sync [:initialize])
(render))
This is my events.cljs:
(ns alpha-journal.events
(:require
[re-frame.core :as rf]))
(rf/reg-event-db
:initialize
(fn [_ _]
{:message "I'm initialized!"}))
Currently I’m not subscribing anywhere as I just wanted to inspect the app db in REPL. Does this possibly cause the error? Any thoughts are much appreciated 🙂 thanksWhoops, just realized I needed to require my events namespace for it to load. @ingesol thank you for the catch! Can someone possibly explain why this is necessary (not sure why requiring events ns causes it to all sync)? Coming from a Redux background there is an obvious place where Redux is loaded (`<Provider store={store}/>), is there a visible place where re-frame is wrapping or initializing all the event handlers, app-db, etc.? Thanks!
re-frame has registries for storing state like events and subscriptions, and they are hidden from you. You only set and get them through keywords. The reason you have to require is because of the way clojurescript compilation works. Namespaces that are not used will not be included/parsed in your program
So when your events ns is not required by anyone, it will not be run during runtime, and then no event registration happening
Hello everyone, I’m currently setting up re-frame-10x with a basic project that is using shadow-cljs only. I got the go-ahead from Thomas Heller that my config looks good. I’m now sure why, but my app-db only shows up correctly in the dashboard when I hot reload my app (change a view file for example). Anyone who got a shadow-cljs app working with re-frame-10x, I would love to hear if you had to do anything special. Here’s my shadow-cljs.edn:
{:deps true
:builds {:app {:target :browser
:output-dir "public/out"
:asset-path "/out"
:modules {:main {:init-fn alpha-journal.core/main}}
:compiler-options {:closure-warnings {:global-this :off}
:closure-defines {"goog.DEBUG" true
"re_frame.trace.trace_enabled_QMARK_" true
"_frame.tracing.trace_enabled_QMARK_" true}
:optimizations :whitespace}
:devtools {:http-root "public"
:http-port 8020
:after-load alpha-journal.core/render
:preloads [devtools.preload
day8.re-frame-10x.preload]}}}}
My deps.edn:
{:paths ["src"]
:deps {thheller/shadow-cljs {:mvn/version "2.8.94"}
binaryage/devtools {:mvn/version "1.0.0"}
cider/cider-nrepl {:mvn/version "0.25.0-alpha1"}
reagent {:mvn/version "0.10.0"}
re-frame {:mvn/version "0.12.0"}
day8.re-frame/tracing {:mvn/version "0.5.3"}
day8.re-frame/tracing-stubs {:mvn/version "0.5.3"}
day8.re-frame/re-frame-10x {:mvn/version "0.6.2"}}}
and my basic app file, core.cljs:
(ns alpha-journal.core
(:require
[reagent.dom :as dom]
[re-frame.core :as rf]
[alpha-journal.events]
[alpha-journal.views :refer [app]]))
(defn render
[]
(dom/render [app]
(js/document.getElementById "app")))
(defn main
[]
(rf/dispatch-sync [:initialize])
(render))
Looking to hear possible issues with my setup. Thanks for the help!