Fork me on GitHub
Ramon Rios11:03:22

Hello everyone! I'm trying to, in a click of a span, replace the field from span to a input.

(defn input-text-brio-nr [brio-nr]
  [:input {:type "text"
           :value brio-nr
           :on-change #(reset! brio-nr (-> % .-target .-value))}])

(defn brio-nr-formatter
  [:span  [:a {:on-click #(input-text-brio-nr brio-nr)} brio-nr]])
On my first attempt, it does not work as expected. So have someone tried to do this? I'm using the brio-nr-formatter on a re-frame datatable
(defn show-table []
   [(t/column {:key [:customer]
               :label (ml/tx "Customer")})
    (t/column {:key [:policy]
               :label (ml/tx "Policy")})
    (t/column {:key [:term]
               :label (ml/tx "Term")})
    (t/column {:key [:settlement]
               :label (ml/tx "Bruto")})
    (t/column {:key [:brio-nr]
               :label (ml/tx "Brio Nr")
               :render-fn brio-nr-formatter})
    (t/column {:key [:brio-nr]
               :label (ml/tx "Verified")})]])


Why not having an if in your view to either display the input or the span based on some arbitrary value you set in the state. Something like edit-mode?

☝️ 8
Ramon Rios16:03:40

I ended up doing that. Thanks

Ramon Rios16:03:11

Now, what i'm trying to do it's the reverse. When i change the focus on the field, it will back to be a span

Ramon Rios17:03:46

I did that, but it's doing in all of the columns and not in only one


That’s because when you save the edit-mode? Value in your state, the path you choose in your map has to be unique. You can save it for example under {:edit-mode? {“unique-id” true}}


So when your state changes and the table is rerendered, only one single cell will effectively become an input and not all of them :)

Ramon Rios09:03:44

Do you know how can i send the id of the object or more data into the render function?

Ramon Rios09:03:58

I was looking on documentation yesterday trying to do that

Ramon Rios09:03:12

And also, a huge thanks for the tips


Lemme read up the docs of the lib you’re using and I’ll get back to you later :)

Ramon Rios09:03:05

thanks a lot


Np 😄😄

Ramon Rios09:03:27

(defn input-text-brio-nr [brio-nr]
  [:input {:type "text"
           :value brio-nr
           :on-blur #(rf/dispatch [:ogm/set-edit-brio-nr false])}])

(defn brio-nr-formatter
  [brio-nr cust]
  (let [editing (rf/subscribe [:ogm/edit-brio-nr])
        cid (:customer-id cust)]
    (println "this is cust" cid)
    (if @editing
      [input-text-brio-nr brio-nr]
      [:span [:a {:on-click #(rf/dispatch [:ogm/set-edit-brio-nr true])} brio-nr]])))

Ramon Rios09:03:11

I got the id, just thinking in how implement your idea of unique way


You can pass cust to your dispatch function and save the true boolean under for example:

(assoc-in db [:edit-mode? cust] true)


and in your subscription you get the current mode out like this: (get-in db [:edit-mode? cust])


Also, pass cust down to the input as well. Its on-blur event will take cust and will do:

(update db :edit-mode? dissoc cust)


And this should work for all the table rows independently 🙂

Ramon Rios10:03:23

Thanks, i'll give a try


So yeah you can simply call in your :render-fn a wrapper that returns your span or input depending on a re-frame subscription


Hello there, I'm trying to do some Web-Socket communication, and there seems to be a bottleneck somewhere. Ideally, I would want to send 1000s of requests and get 1000s of responses within a few seconds. Google says it should be possible with a million so thousands are probably not science fiction. Now, here is how it works: 1. Each requests starts by dispatching an event that triggers a :ws-send effect, 2. When a response comes through the socket, it triggers a :proscess-response event. 3. This :process-response event converts the response to edn and triggers another event :ws-command


4. :ws-command finds out from the data which db event to dispatch. 5. and this final event updates the app-db with the data we got from the response.


Now, this is maybe a little rube-goldebergesque, but I'm not sure what influences performance the most.


Why not just profile it in the browser?


good call 🙂


How do folks generally organize their namespaces as a re-frame codebase grows? I have all my view code under a my-project.components.* umbrella of namespaces, but wondering about other stuff. The re-frame template defines my-project.subs and, but as it grows I think I will need to break down each into features/component groups, while still keeping the event/subscription keywords in the higher-level namespaces, like this:

  [ :as locations]
  [ :as providers]
  ;; etc.
  [re-frame.core :as r]))

(r/reg-event-fx ::search-locations! locations/search!)
(r/reg-event-fx ::search-providers! providers/search!)
This way I maintain a single entry point each for components into events/subs. Thoughts?


I like having subs and events in one namespace related to the feature I’m working on


do you mean one combined namespace for both subs and events?


(ns my-project.locations
  [re-frame.core :as r]))

(defn search! [] ,,, )
(defn update-results [] ,,, )

(r/reg-event-fx ::search! search!)
(r/reg-sub ::search-results update-results)
so something like that?


I could see how that could be's already a bit of a pain jumping between views/subs/events


yeah exactly


often, if I want to change the way I’m storing something in the app-db, I’ll need to update both events and subs

💯 4

it’s nice if they’re located together

✔️ 4