This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-15
Channels
- # announcements (2)
- # babashka (27)
- # beginners (53)
- # boot (3)
- # calva (5)
- # cider (1)
- # clj-kondo (46)
- # cljdoc (38)
- # cljs-dev (40)
- # cljsrn (1)
- # clojars (5)
- # clojure (61)
- # clojure-europe (124)
- # clojure-germany (3)
- # clojure-losangeles (6)
- # clojure-nl (12)
- # clojure-uk (11)
- # clojurescript (44)
- # clojureverse-ops (7)
- # datomic (13)
- # events (3)
- # introduce-yourself (1)
- # jackdaw (5)
- # lsp (115)
- # malli (1)
- # off-topic (16)
- # polylith (2)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (10)
- # sql (2)
- # timbre (1)
- # tools-deps (30)
- # vim (34)
- # xtdb (20)
e.g. "WARNING: Use of undeclared" means my build is broken. I want it to throw it's toys out of the pram... not stoically push on regardless.
Here's my current workaround using a Makefile...
prod-build:
clj-kondo --lint src/cljs --fail-level warning
clojure -M -m cljs.main -co prod.cljs.edn -O advanced -c
Shadow has https://shadow-cljs.github.io/docs/UsersGuide.html#warnigs-as-errors, not sure about the base cljs compiler
There really should be a bot which links to shadow-cljs for each known CLJS compiler niggle.
I have an re-frame fx set-logged-in that is triggered on page load:
(rf/reg-fx
:set-logged-in
(fn [magic]
(go
(rf/dispatch
[:set-logged-in'
(<p! (.. ^js magic -user (isLoggedIn)))]))))
(reg-event-db
:set-logged-in'
(fn [db [_ logged-in?]]
(assoc db :logged-in? logged-in?)))
And the problem is that (<p! (.. ^js magic -user (isLoggedIn)))
is true after a few seconds (takes a while for the magic api to set isLoggedIn to true in the backend) and not immediately on pageload, so that means even though I want the value of :logged-in? to be true, it shows up as false because :logged-in? is set before the value of the promise is changed from false to true. How can I tweak the code so that I can wait for a few seconds on isLoggedIn so that I know for sure that isLoggedIn will or won’t return true and then set the :logged-in? value?
Basically I want to change :logged-in? whenever (<p! (.. ^js magic -user (isLoggedIn)))
changes, but currently I can only set it once on pageload.
Also I don’t understand how in the documentation they manage to do this using useEffect:
useEffect(() => {
setUser({ loading: true });
magic.user.isLoggedIn().then(isLoggedIn => {
return isLoggedIn ? magic.user.getMetadata().then(userData => setUser(userData)) : setUser({ user: null });
});
}, []);
https://magic.link/posts/magic-react-express
Does useEffect somehow know that await magic.user.isLoggedIn()
has changed? (I believe the .getMetadata() part can be ignored for now)
I implemented this is react too:
(let [[logged-in? set-logged-in] (useState false)
_ (useEffect (fn []
(.then
(.. magic -user (isLoggedIn))
(fn [logged-in?]
(set-logged-in logged-in?)
#_(e/set-logged-in' logged-in?)))
[]))] ...)
But the same problem arises. I’m not logged in the redirect after the magic link but have to refresh the page to be logged inIs there any documentation on how to actually require macros defined in bootstrapped cljs?
(Or even get bootstrapped clojurescript to require the correct file without explicitly using :require-macros
but you can subvert it - basically there is a hidden namespace which is the same name as the original but + $macros
Oh, I see. So self-hosted clojurescript is just not supposed to have macros then, correct?
in self-hosted it becomes a problem right away - because you can't have these things live in the same place
So I guess, the question then becomes, how do I use these macros. What I've tried so far is:
;; example/core.clj
(ns example.core)
(defmacro add-three [x]
`(+ ~x 3))
;; example/core.cljs
(ns example.core
:refer-macros [example.core :refer [add-three]])
(println (add-three 4))
But it seems to be trying to call add-three
as a function.As in this post: http://nbeloglazov.com/2016/03/07/getting-started-with-self-hosted-cljs-part-2.html
The compiled output for core.clj
is:
goog.provide("example.core$macros");
var ret__38016__auto___49 = bob.core$macros.add_three = (function example$core$macros$add_three(_AMPERSAND_form,_AMPERSAND_env,x){
return cljs.core.sequence.call(null,cljs.core.concat.call(null,(new cljs.core.List(null,new cljs.core.Symbol("cljs.core","+","cljs.core/+",(-342754435),null),null,(1),null)),(new cljs.core.List(null,x,null,(1),null)),(new cljs.core.List(null,(3),null,(1),null))));
});
(example.core$macros.add_three.cljs$lang$macro = true);
Which looks right.