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 oneIs 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
@lloydshark 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?
Yes.
@p-himik 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 πͺ
There are many other tools that help during development of course.
They are in separate namespaces but I donβt think that is the problem
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
okay thank you I give it a shot
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.
Thanks again, deleted the post on #reagent π
there's a couple issues with your code
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
https://reactjs.org/docs/refs-and-the-dom.html#caveats-with-callback-refs
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
Thank you a lot for this detailed explanation π
I will give it another shot with the stuff I just learned π
@lilactown 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 πyw!