Fork me on GitHub
#clojurescript
<
2019-12-04
>
MityaSaray09:12:03

is there a good configuration handling post for cljs?

restenb11:12:46

anybody use https://github.com/clj-commons/secretary for client-side routing?

restenb11:12:06

how can I navigate to a certain route from within a re-frame event?

restenb11:12:52

trying to "cheat" by doing (defn goto [path] (set! (.-href js/location) path)) but doesn't work, secretary seems unable to perform the parameter destructuring

restenb11:12:25

the docs state that by using named routes you can run them as functions, f.ex. (my-route {:param "foo"})should execute the corresponding defroute but that also seems to achieve nothing

p-himik11:12:21

I know that's not what you asked, but given that you appear to just having started with secretary and you also use re-frame, you may be interested in https://github.com/ingesolvoll/kee-frame which deals with this and other problems related to navigation in SPAs written with re-frame. By default, it uses a different routing library (reitit, I believe), however it has examples on how with little code you can adapt it to any routing library. I use it with bidi, for example.

👍 4
restenb11:12:12

hi, i'm aware of kee-frame, in fact I used to work with the guy who created it 😛

👍 4
restenb11:12:36

just don't have time right now for a larger frontend rewrite since this is an old project i'm updating to clojure 1.10

restenb11:12:08

the error message seen is Uncaught Error: No protocol method IMapEntry.-key defined for type cljs.core/LazySeq: (:id "1")

restenb11:12:28

seems to originate from secretary.core.locate-route

gklijs11:12:44

I recently added routes, maybe as example it might help. I liked it basiccaly you only have to match parts of the url with parts of the db, and then it works. https://github.com/openweb-nl/kafka-graphql-examples/blob/master/frontend/src/cljs/nl/openweb/bank/routes.cljs

restenb11:12:21

point is everything used to work, until I updated all the project dependencies.

restenb11:12:42

routing via clicking links with hrefstill does work fine, but not when trying to call the routes dynamically or alter js/location

restenb11:12:21

how does that work with bidi?

jjttjj17:12:02

With the google closure ui autocomplete component (demo: https://google.github.io/closure-library/source/closure/goog/demos/autocomplete-basic.html), does anyone know how I attach a listener to a value from the dropdown being selected?

jjttjj17:12:12

I've been trying things like

(.listen my-ac-component
   goog.ui.ac.AutoComplete.EventType/SELECT
   (fn [e] (js/console.log e)))
But no luck

hiredman17:12:15

I believe you use goog.events.listen

jjttjj17:12:13

Ok figured it out, I guess you need to listen to the renderer and not the autocomplete object:

(defn ac []
  (let [el      (input)
        matcher #js{}
        input-handler (goog.ui.ac/InputHandler. nil nil false)
        _             (set! (.-requestMatchingRows matcher)
                            (fn [q max-matches cb]
                              (cb q (get-matches q))))
        renderer      (goog.ui.ac/Renderer.)
        ac            (ac/AutoComplete. matcher
                                        renderer
                                        input-handler)]
    (.listen renderer
             goog.ui.ac.AutoComplete.EventType/SELECT
             (fn [e] (js/console.log e)))

    (.attachAutoComplete input-handler ac )
    (.attachInputs input-handler el )

    el))

folcon18:12:29

I’ve been trying to use unicode property escapes in regex and I’m just getting errors… Any idea how to do the equivalent of this: var regex = new XRegExp("\\p{L}")

folcon18:12:41

Ok, worked this out :)…

(re-pattern "(?u)(\\p{L}+)")
I was missing out using (?u).

ec18:12:02

What do I need to do make a sub update when a field that its dependent on the db updates?

(rf/reg-sub
 ::refs
 (fn [db]
   (let [refs (-> db :card-meta :refs)]
     (println "Active: " (:active refs))
     ((:active refs) refs))))
When the (-> db :refs :active) updates by some event this sub doesnt update, even tho println runs?

celwell18:12:58

Where are you using (deref'ing) the sub?

ec18:12:07

here

(defn ref-list []
  (let [refs (rf/subscribe [::subs/refs])]
    [:ul.ref-list 
     (doall (for [ref @refs]
              ^{:key ref}
              [:li [:h4 (:id ref)]]))]))

Lu18:12:09

Where is located the ref-list component call?

ec18:12:00

Here

(defn ref-view []
  [:div.header {:style {:margin-top "0.50em"}}
   [ref-list]])

(defn main-panel []    
  (add-shortcuts!)
  (fn []
    [:div.container  
     [ref-list]]))

celwell18:12:50

Try:

(defn ref-list []
  (let [refs (rf/subscribe [::subs/refs])]
    (fn []
      [:ul.ref-list 
       (doall (for [ref @refs]
                ^{:key ref}
                [:li [:h4 (:id ref)]]))])))

ec18:12:26

that didnt work :G

lilactown18:12:26

((:active refs) refs) what does this do?

ec18:12:35

refs is {:to [] :from [] :active :to} extracts :active and gets it from refs

Lu18:12:34

Can you add printline in ref-list before doall and deref the refs there? Just curious to see if you get the updated value out of the loop

ec18:12:42

Tried

(defn ref-list []
  (let [refs (rf/subscribe [::subs/refs])]
    (println "UPDATE!")
    [:ul.ref-list 
     (doall (for [ref @refs]
              ^{:key ref}
              [:li [:h4 (:id ref)]]))]))
And println doesnt get called

lilactown18:12:56

for giggles, try dereferencing it outside of the for

lilactown18:12:29

e.g. (let [refs @(rf/subscribe [::subs/refs)] … and then use the value inside of the for instead

lilactown18:12:49

AFAICT your code should work, so I’m just trying to remove confounding things that look slightly suspect

ec18:12:26

it didnt work too :G

ec18:12:45

My event handler

(rf/reg-event-db
 ::toggle-ref-list
 (fn [db [_]]
   (println "CURRENT: " (-> db :refs :active))
   (update-in db [:refs :active] #(if (= % :to) :from :to))))
which seems working fine

lilactown18:12:07

what’s the actual value of the subscription being returned?

lilactown18:12:33

have you added any refs to it or are they both [] ?

ec19:12:23

Yeah nope, but DB is updated from this

:refs        {:to [{:id "SOMEID"}] :from [{:id "ANTERID"}] :active :to}
to
:card-meta {          
:refs        {:to [{:id "SOMEID"}] :from [{:id "ANTERID"}] :active :to}}
this... Works fine after adding :card-meta to update-in

ec19:12:35

Perks of untyped language...

ec19:12:48

sorry to make you guys go through this

lilactown19:12:15

haha! no worries

celwell18:12:36

If both :to and :from are [] then it won't update the component

☝️ 4
ec19:12:31

If you had N different commands/shortcuts that can be invoked from your re-frame app would you register N different event-handlers that takes :CMD-A-INVOKED... or a single handler that takes CMD-INVOKED {:id .. :args} ? Second one offers more control but feels like re-inventing reframe?

shaun-mahood20:12:47

@UFHB0T69M You'll probably get a better response in #re-frame - for my part, I would probably group them into a a single event-handler only where they were logically related and expected the same kind of arguments. For the general case, it seems like normal re-frame events already cover your example - (dispatch [:cmd-a args]) seems pretty clear. Without the details it's a little hard to know for sure. If you want something specific outside of the regular dispatch, you could also look into registering a new effect so that your event handler you could return something like {:invoke [:cmd-a args]}

celwell20:12:04

I personally lean towards the former (more even handlers). You might also find this interesting depending on the use case: https://github.com/vimsical/re-frame-utils/blob/master/src/vimsical/re_frame/fx/track.cljc