Fork me on GitHub
Ovidiu Stoica06:05:34

Does anyone have any idea why re-frame won’t recognise a handler i have? Handler :

  (fn [{:keys [url success-event error-event success-path]}]
    (GET url
         (cond-> {:headers {"Accept" "application/transit+json"}}
                 success-event (assoc :handler
                                         (conj success-event
                                               (if success-path
                                                 (get-in % success-path)
                 error-event   (assoc :error-handler
                                         (conj error-event %)))))))
event-fx that dispatches it:
  (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 one

Ovidiu Stoica06:05:04

They 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

Ovidiu Stoica07:05:14

@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?

Ovidiu Stoica07:05:46

@U2FRKM4TW thank you. I am a beginner with clojurescript so any other good resources like that one are much apreciated 😄


Also 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, or

❤️ 3
Ovidiu Stoica07:05:41

Thank you, that fixed it 💪


There are many other tools that help during development of course.


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"}})))))
        (fn [el]
            #js {:state
                  #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 🙂

👍 3

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


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 🙏


@U4YGF4NGM awesome it seems to work 💪

(defn result-view2 [source]
  (let [!view (atom nil)
        !mount (fn [el]
                     #js {:state
                           #js {:doc (with-out-str (fipp '(load-db db-name "resources")))
                                :extensions extensions})
                          :parent el})))]
     {:display-name "result-view"
      (fn []
        (println "hallo?"))
      (fn [source]
        [:div {:ref !mount}])}))) 
👆 thanks again 😇