This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-04
Channels
- # adventofcode (154)
- # announcements (1)
- # babashka (8)
- # beginners (28)
- # bristol-clojurians (3)
- # calva (131)
- # cider (43)
- # clj-kondo (14)
- # clojure (135)
- # clojure-europe (1)
- # clojure-italy (7)
- # clojure-madison (1)
- # clojure-nl (6)
- # clojure-spec (8)
- # clojure-uk (90)
- # clojurescript (47)
- # core-async (9)
- # cryogen (4)
- # cursive (12)
- # datomic (9)
- # emacs (7)
- # fulcro (5)
- # graalvm (56)
- # joker (4)
- # juxt (1)
- # leiningen (6)
- # off-topic (62)
- # pathom (4)
- # pedestal (2)
- # reagent (2)
- # reitit (5)
- # ring (2)
- # schema (4)
- # shadow-cljs (133)
- # sql (38)
- # tools-deps (10)
- # vim (28)
is there a good configuration handling post for cljs?
anybody use https://github.com/clj-commons/secretary for client-side routing?
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
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
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.
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
the error message seen is Uncaught Error: No protocol method IMapEntry.-key defined for type cljs.core/LazySeq: (:id "1")
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
routing via clicking links with href
still does work fine, but not when trying to call the routes dynamically or alter js/location
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?
I've been trying things like
(.listen my-ac-component
goog.ui.ac.AutoComplete.EventType/SELECT
(fn [e] (js/console.log e)))
But no luckOk 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))
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}")
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?here
(defn ref-list []
(let [refs (rf/subscribe [::subs/refs])]
[:ul.ref-list
(doall (for [ref @refs]
^{:key ref}
[:li [:h4 (:id ref)]]))]))
Here
(defn ref-view []
[:div.header {:style {:margin-top "0.50em"}}
[ref-list]])
(defn main-panel []
(add-shortcuts!)
(fn []
[:div.container
[ref-list]]))
Try:
(defn ref-list []
(let [refs (rf/subscribe [::subs/refs])]
(fn []
[:ul.ref-list
(doall (for [ref @refs]
^{:key ref}
[:li [:h4 (:id ref)]]))])))
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
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 callede.g. (let [refs @(rf/subscribe [::subs/refs)] …
and then use the value inside of the for
instead
AFAICT your code should work, so I’m just trying to remove confounding things that look slightly suspect
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 fineYeah 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-inIf 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?
@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]}
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