This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-07
Channels
- # announcements (1)
- # babashka (31)
- # beginners (54)
- # biff (3)
- # calva (22)
- # cider (13)
- # circleci (1)
- # clj-kondo (6)
- # cljsrn (2)
- # clojure (113)
- # clojure-europe (58)
- # clojure-mexico (5)
- # clojure-nl (3)
- # clojure-uk (7)
- # clojurescript (81)
- # cursive (20)
- # datomic (33)
- # events (3)
- # fulcro (29)
- # introduce-yourself (1)
- # meander (78)
- # off-topic (60)
- # om-next (2)
- # podcasts-discuss (1)
- # re-frame (8)
- # reagent (5)
- # reitit (20)
- # remote-jobs (1)
- # shadow-cljs (24)
- # spacemacs (10)
- # sql (8)
- # tools-deps (22)
- # xtdb (16)
how do I require an npm module that has a slash in it? Im trying to import and put quotes around the imported module name but it isn't working properly
for example, if the nodejs require is:
require("hello/world")
im trying
(:require ["hello/world" :as hello-world])\
It might depend on the build tool that you're using. Shadow-cljs should handle it just fine.
Also check what that module actually says in the "main"
key in its package.json
.
If that doesn't provide any clues, you can always use a full path relative to node_modules
.
I have the following issue that I submitted on the reagent github, but haven’t heard back and don’t know the solution of! https://github.com/reagent-project/reagent/issues/543
I’m implementing the following: https://github.com/arunoda/use-magic-link And so far I have this:
(:require ["use-magic-link" :default useMagicLink])
(defn login []
(let [!email (atom nil)
auth (useMagicLink "pk_live_23456787878579")]
[:div
(if (. auth -loggedIn)
[:div {:on-click #(. auth logout)} "Logout"]
[:div
[:input {:on-change #(reset! !email (-> % .-target .-value))}]
[:div {:on-click (fn [] (. auth login @!email))} "Login/Sign Up with email"]])]))
And I’m using it as [:f> login] in a parent component. But I’m getting this error:
core.cljs:36 Uncaught TypeError: module$node_modules$use_magic_link$dist$use_magic_link.default is not a function
at cmp.humboi$core$login [as reagentRender] (core.cljs:36)
at eval (component.cljs:86)
at Object.reagent$impl$component$wrap_render [as wrap_render] (component.cljs:91)
at Object.reagent$impl$component$do_render [as do_render] (component.cljs:117)
at eval (component.cljs:73)
at Object.reagent$ratom$in_context [as in_context] (ratom.cljs:44)
at Object.reagent$ratom$deref_capture [as deref_capture] (ratom.cljs:57)
at Object.reagent$ratom$run_in_reaction [as run_in_reaction] (ratom.cljs:539)
at cmp.re_frisk$reagent$impl$component$wrap_funs_$_render [as render] (component.cljs:73)
at finishClassComponent (react-dom.development.js:17486)
Check what useMagicLink
is with js/console.log
. Sometimes it's not what it's supposed to be.
ha it’s undefined
yeah changing to as works, which seems like a #shadow-cljs bug
It's not a bug, it's well documented: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
I’m writing the first code block from here in cljs: https://www.npmjs.com/package/@magic-ext/oauth?activeTab=readme And I have the following:
(Magic. "pk_live_ldshfsjdfsfasdf"
#js {:extensions [(OAuthExtension.)]})
but this is giving me the following cryptic error:
Uncaught TypeError: Cannot read property 'compat' of null
at checkExtensionCompat (sdk.js:21)
at eval (sdk.js:68)
at Array.forEach (<anonymous>)
at SDKBase.prepareExtensions (sdk.js:67)
at new SDKBase (sdk.js:107)
at Function.humboi$core$login (core.cljs:37)
at Function.eval [as cljs$core$IFn$_invoke$arity$2] (core.cljs:3925)
at Function.eval [as cljs$core$IFn$_invoke$arity$2] (core.cljs:3961)
at Object.reagent$impl$component$functional_wrap_render [as functional_wrap_render] (component.cljs:380)
at Object.reagent$impl$component$functional_do_render [as functional_do_render] (component.cljs:393)
How to fix this?the cljs looks correct I think. maybe you need to init thing first? e.g. const res = await magic.oauth.getRedirectResult();
I have this piece of code, in which I’m using reset! to set the value of an atom:
(defn login []
(let [
magic (new-magic)
!social-logged-in (atom nil)
_ (go (js/console.log "is logged in " (<p! (.. magic -user (isLoggedIn))
)))
_ (go (reset! !social-logged-in
(<p! (.. magic -user (isLoggedIn))
)))
_ (js/console.log "social logged in " @!social-logged-in)
]
))
As you can see, there are two logs one that prints A
_ (go (js/console.log "is logged in " (<p! (.. magic -user (isLoggedIn))
)))
and the other that prints B:
_ (js/console.log "social logged in " @!social-logged-in)
Even though I’m setting the value of !social-logged-in, the values that A and B are printing aren’t the same. Why is that?
I’m getting “is logged in true”
“social logged in null”is it being printed in that order? I would expect it to print in the opposite order
either way there's no explicit order dependency between the reset!
and the _ (js/console.log "social logged in " @!social-logged-in)
.
maybe try something like:
(defn login []
(let [
magic (new-magic)
!social-logged-in (atom nil)
_ (go (js/console.log "is logged in " (<p! (.. magic -user (isLoggedIn))
)))
reset-ch (go (reset! !social-logged-in
(<p! (.. magic -user (isLoggedIn))
)))
_ (go
(<! reset-ch)
(js/console.log "social logged in " @!social-logged-in))
]
))
is <! valid in cljs?
yes they are printed in that order
yes, <!
is valid in cljs. it's <!!
that doesn't work
yeah that does print true for both, but why is <! required?
you want to print the result after the reset!
has been run
but how will this fit into the rest of the code? this is what follows the let bindings:
[:div
(if @!social-logged-in
[:div {:style {:cursor :pointer}
:on-click #(.. magic -user (logout))} "Logout"]
[:div {:style {:display :flex :flex-direction :row}}
[:img
{:on-click (fn [event]
(go
(<p! (.. magic -oauth
(loginWithRedirect
#js {:provider "facebook"
:redirectURI
(.. js/window -location -origin)})))))
:src ""
:style {:cursor :pointer :height 50}}]])]
there’s a conditional rendering with if that depends on !social-logged-inwhat UI library are you using?
reagent
is the atom an r/atom
or the built in one?
built in
it should be an r/atom
so that it will rerender when the value is updated
I am trying to create a simple logging thread in clojurescript. I am following the examples in the learn-clojurescript ebook. My code is simple..
(ns tstcljs.core
(:require [clojure.core.async :as async :refer [<! >! chan go-loop]))
(def echo-chan (chan))
(go (prn (<! echo-chan)))
(>! echo-chan "hello")
At the last line I get the error:
#object[Error Error: >! used not in (go ...) block]
Why?
heh ok. total newbee here... thanks man!!
Is there something like IPrintWithWriter
in clojurescript, but can emit non-string values?
I’m not sure what you mean here. Emit to where? If it’s the output stream then non strings can be converted, can’t they? Or am I missing something important here?
For instance, I have code in a defrecord
that emits the object as tagged data (specifically to emit in edn):
IPrintWithWriter
(-pr-writer [this writer _] (-write writer (str this)))
@U051N6TTC I have my own *print-fn*
, that can handle non-string values. I'd just like to send them through the println
function if possible.
If so, I don't want non-strings to be converted to strings. I want my custom *print-fn*
function to get non-strings and embed them in the DOM.
Although I could be missing something. There seems to be a lack of documentation for the -pr-writer
function. 😞
str
emits a string, yes. That’s what I sent to the -write
function in my version of -pr-writer
, but what else do you want to send to -write
? Do you want to serialize something else into bytes?
In my case, I have an object which wraps a number, and the string form is #a/n[1234]
. By extending the object to IPrintWithWriter
and having it call -write
with the string form, then I get it printing properly at the repl, etc.
I’m still trying to understand what you want to do, sorry
For context, I'm making this for clojurescript: https://www.youtube.com/watch?v=8htgAxJuK5c
And by that, I don't mean a serialization of the dom node. I'd like to print out the dom node itself. (If I have to pass through a serialize/deserialize layer than oh well. I'll get around to it later.)
But what do you mean by “print out the dom node”? Because if you’re printing it, then it’s a string, right?
Nope. Consider a web browser's console. When you print a DOM node to the console using console.log
, you get a live object of that DOM node.
actually, I did not know that. I thought that once it hit the console that it was a static snapshot rendered as a string
Ah, nope. It actually is a thing that initially throws off a lot of devs, because javascript objects are mutable.
And if the object gets mutated after its printed out to the console, the object in the console changes.
So if you want a static render, you need to stringify and reparse it. (Per the MDN page anyway)
If that's not possible I'll eventually set up a mechanism to do the serialize/deserialize trick.
(deftype MyData [data]
IPrintWithWriter
(-pr-writer [this writer _] (-write writer {:data data})))
Then:
=> (MyData. 5)
{:data 5}
@U051N6TTC Ah, sadly it looks like it does cast it to a string. Oh well. Thanks again. 🙂
If not, then does it need to be a standard protocol? Would it be possible to create your own, and then extend desired types to it? (Extending object
for the default case)
@U051N6TTC Ultimately,, it's going into a <div>
in the DOM that's meant to look like a console.
But ya, it doesn't have to use a standard protocol. I had just hoped to be able to, that way users don't have to add :refer-clojure :eexclude [println ...])
.
But that seems like it would only be necessary if you’re trying to insert a printed version into the DOM? Couldn’t you allow the standard printing to take place elsewhere, and then use your protocol for DOM insertion? I’m sorry. I keep feeling like I’m missing obvious things when we’re talking on this.
I am building an IDE in the browser using cljs.js. In this IDE, users both write and run their code directly in the browser.
In addition to supporting vanilla clojurescript, the IDE needs to support VISRs, which are mix of a macro, combined with a renderer, and some state (probably using deftype
).
Users can print a VISr like any other object, but when they do, I want it to show up in the repl as a rich object, and not just its textual representation.
And I would ideally let users do the printing with standard print functions (`print`, println
,`pprint`,etc.)
Does that make any more sense @U051N6TTC?
Something like: https://docs.racket-lang.org/reference/port-lib.html?q=print-special#%28def._%28%28lib._racket%2Fport..rkt%29._make-pipe-with-specials%29%29 (`make-pipe-with-specials`) in Racket.