This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-22
Channels
- # announcements (2)
- # babashka (64)
- # beginners (41)
- # calva (4)
- # cider (1)
- # clj-kondo (78)
- # cljdoc (31)
- # cljsrn (4)
- # clojars (2)
- # clojure (109)
- # clojure-germany (1)
- # clojure-italy (8)
- # clojure-nl (2)
- # clojure-spec (8)
- # clojure-uk (28)
- # clojurescript (61)
- # code-reviews (2)
- # cryogen (2)
- # cursive (23)
- # datomic (21)
- # duct (15)
- # fulcro (37)
- # graalvm (17)
- # graphql (3)
- # jackdaw (3)
- # joker (11)
- # lein-figwheel (4)
- # malli (42)
- # off-topic (97)
- # pathom (4)
- # pedestal (1)
- # portkey (3)
- # re-frame (7)
- # reagent (13)
- # reitit (2)
- # shadow-cljs (54)
- # spacemacs (1)
@zelark failed because of coercion? you had defined the :id
as integer?
and "b"
was a string.
@ikitommi yes it is, but I want to handle the coercion exception. I realized that coercion happens automatically, while the documentation says you have to manually do it.
in reitit.frontend/match-by-path
the docs might not be in sync, sorry for that. with reitit.core
, matching path and coercion are two separate steps. with reitit.frontend
there are things bundle to make it… easy.
Exactly!
Now I got it. But is there a way to catch the exception from match-by-path?
Hm, what if user specifies a wrong url: items/12a? I’d rather want to show 404 instead of an error.
oh, the reitit.core/match-by-path
never throws, only the coercion in reitit.frontend/match-by-path. Just
try-catch` it?
Yeah, but the problem is that I don’t understand where I need to catch
it.
I’ll show you the code
(def router
(reitit.frontend/router
routes
{:conflicts nil
:compile reitit.coercion/compile-request-coercers}))
(defn on-navigate [new-match]
(if new-match
(rf/dispatch [:set-current-route new-match])
(rf/dispatch [:page-not-found])))
(defn init-routes! []
(js/console.log "initializing routes") ;; TODO: get rid of it.
(reitit.frontend.easy/start!
router
on-navigate
{:use-fragment true}))
I would suggest writing an issue to reitit to provide a way to handle the exception in an easy way.
Ok, I’ll do
Thank you for supporting
currently, the match-by-path
is called before calling your on-navigate
so no easy way to do that: https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/history.cljs#L123
yeah, thanks, initially I didn’t think it related to reitit, just an exception I cannot catch for some reason, that’s why I used this channel.
I've discovered promises in Clojurescript : ). I understand that the promise value cannot escape the promise chain, ie the chain won't return the value, but yet another promise. what is the best practice in Clojurescript for passing on the value, eg to another function? someone suggested assigning it atom, but it's plainly changing the state; does not this beat the premise of immutable data?
> what is the best practice in Clojurescript for passing on the value, eg to another function? Just passing it as a parameter? I'm not sure what you're asking.
just chain handlers... either using the .then
fn directly, or with a lib like funcool/promesa
which gives you some nice binding sugar too - https://cljdoc.org/d/funcool/promesa/4.0.2/doc/user-guide#promise-composition
@U2FRKM4TW Say in the (-main) function I fetch an api call that returns a promise. Now, to process the resutlt I either have to send it to another function as a value. Which means I am branching execution to another function everytime I call an API. If I want to continue to process the result in (-main) I either need to send it to a channel and take! from it later on, or to reset! an atom and deref it later in the main. I am looking for best practice, since i've just learned about promieses.
@U96LS78UV I see. Yeah, just do what mccraigmccraig said. reset!
and deref
will not work because JS has only 1 thread. And even if you employ asynchronous code, there's still no guarantee by itself that deref
will be executed after reset!
.
does or how does shadow-cljs or cljs in general handle polyfills/transpilation (for :browser) ? i.e. js/Promise in IE11, or is it delegated to a bundler (webpack)
@lilactown just tried shadow-cljs sample project (https://github.com/shadow-cljs/quickstart-browser) in release build and Promises are missing in IE11, even with :compiler-options {:output-feature-set :es3}
@birdspider polyfills depend on where they are used. did you use them in CLJS code or some included JS code?
i used js/Promise
in the src/starter/browser.cljs
of the sample project, which compiles to main.js
which is the sole js in the index.html
@thheller ah I see, it a cljs flag, I was looking at the shadow-cljs doc, thxs
@thheller btw, this should be update in the doc @lilactown posted, because currently the safest default and supports most browsers in active use (including IE10+)
seems not to be correct without the :rewrite-polyfills
In the past I've ended up using something like http://polyfill.io to detect the browser being used and ship a minimal polyfill
@lilactown oh thats cool, didn't know that site
@lilactown does it react on User-Agent ?
I'm getting Execution error (ClassNotFoundException) at http://java.net.URLClassLoader/findClass (URLClassLoader.java:381). com.google.common.collect.Stream when requiring reagent, does anyone know what's up?
now I have to figure out what Guava is
@thheller that solved it, on to the next reagent error
can't find variable .......$react_dom$index
(require 'reagent.core)
(reagent.core/render [:h1 "Hello World"] (.-body js/document))
undefined is not an object (evaluating 'reagent.core.render.call')
just starting a REPL with clj -m cljs.main
I don't, but I don't like this direction really, guessing what the error is, I don't think it's a good investment of my time
i'm done dealing with implicit errors
I'm sure its a simple error though but I haven't used the default tools in a long time so I can't offer any help really
why is software broken all the time? it's shocking
did you went through this https://clojurescript.org/guides/quick-start ?
thanks for the help, gonna leave it for now. I'll try again later