This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-29
Channels
- # announcements (3)
- # aws (12)
- # babashka (11)
- # beginners (46)
- # calva (10)
- # cider (6)
- # clara (3)
- # cljdoc (6)
- # cljs-dev (13)
- # cljsrn (2)
- # clojure (49)
- # clojure-europe (2)
- # clojure-gamedev (1)
- # clojure-germany (22)
- # clojure-uk (2)
- # clojurescript (28)
- # clojureverse-ops (8)
- # conjure (6)
- # cursive (2)
- # emacs (1)
- # figwheel-main (9)
- # heroku (12)
- # jobs-discuss (1)
- # malli (10)
- # off-topic (1)
- # practicalli (8)
- # re-frame (25)
- # reagent (6)
- # shadow-cljs (24)
- # testing (10)
- # vscode (4)
Does anyone have any idea why re-frame
won’t recognise a handler i have?
Handler :
(rf/reg-fx
:ajax/get
(fn [{:keys [url success-event error-event success-path]}]
(GET url
(cond-> {:headers {"Accept" "application/transit+json"}}
success-event (assoc :handler
#(rf/dispatch
(conj success-event
(if success-path
(get-in % success-path)
%))))
error-event (assoc :error-handler
#(rf/dispatch
(conj error-event %)))))))
event-fx that dispatches it:
(rf/reg-event-fx
:messages/load
(fn [{:keys [db]} _]
{:ajax/get {:url "/api/messages"
:success-path [:messages]
:success-event [:messages/set]}}))
And i get this in the console:
re-frame: no handler registered for effect: {ns: "ajax", name: "get", fqn: "ajax/get", _hash: 1697424003, cljs$lang$protocol_mask$partition0$: 2153775105, …} . Ignoring.
I am kinda lost on this oneThey are in separate namespaces but I don’t think that is the problem
Is the namespace that defines the :ajax/get handler definitely loaded?
That, and also seems like you would benefit from installing https://github.com/binaryage/cljs-devtools
@U4T99SHSB I think you are correct. The namespace that has the ajax handler is not required in any other place. Would simply requiring it in the main ns solve this?
@U2FRKM4TW thank you. I am a beginner with clojurescript so any other good resources like that one are much apreciated 😄
Also https://github.com/binaryage/dirac then, but I'm not sure whether it works with shadow-cljs right now. And, well, shadow-cljs if you work with NPM packages a lot. And since you're using re-frame, https://github.com/Day8/re-frame-10x or https://github.com/flexsurfer/re-frisk
Thank you, that fixed it 💪
Hey, I'm trying to get a component with react ref
and re-frame sub
working. My problem is, that when data gets dispatched a new "view" is created instead of updating the existing one. This probably ain't that hard, but I'm fairly new to reagent/re-frame. This is what I've got so far
(defn result-view [source]
(let [!view (atom nil)]
(fn [source]
;; update the ref
(when-let [v @!view]
(. v (dispatch (. (. v -state)
(update #js {:changes {:from 0 :insert "0"}})))))
[:div
{:ref
(fn [el]
(reset!
!view
(EditorView.
#js {:state
(.create
EditorState
#js {:doc (with-out-str (fipp source))
:extensions extensions-read-only})
:parent el})))}])))
(defn result-box []
(let [source (rf/subscribe [:results])]
(fn []
(let [[_ form] @source]
[:div {:class "code-box"}
[result-view form]]))))
I'm really grateful for any pointer how to get this running 😊subscribe
returns a Reagent reaction, so this question isn't really re-frame-specific.
If you don't get an answer here, I'd try asking in #reagent
The "if you don't get an answer here" was an important part. :) In general, you should wait for at least a few hours. People are in different time zones and have different schedules.
I think the one that's biting you rn is that you're passing in a new function to the :ref
prop every render, which is causing React to reinitialize the ref
if you move the ref fn that creates the EditorState outside of the inner render fn of your form-2 component, then it should stop recreating it every render
I'm guessing that calling .dispatch
on the view during render with some dummy data is just a test you're doing, but I'm inferring that you want to render the current source
passed to the results-view
component in the editor
in that case, you'll want to use a form-3 component that has a component-did-update
method which will dispatch the update to the view immediately after a successful render. this way, your render fn stays pure and you won't run into weird bugs later
@U4YGF4NGM awesome it seems to work 💪
(defn result-view2 [source]
(let [!view (atom nil)
!mount (fn [el]
(reset!
!view
(EditorView.
#js {:state
(.create
EditorState
#js {:doc (with-out-str (fipp '(load-db db-name "resources")))
:extensions extensions})
:parent el})))]
(r/create-class
{:display-name "result-view"
:component-did-update
(fn []
(println "hallo?"))
:reagent-render
(fn [source]
[:div {:ref !mount}])})))
👆
thanks again 😇