Fork me on GitHub
#clojurescript
<
2021-11-02
>
Ty00:11:36

Any recommendations for how to approach WebGL stuff with cljs? I've seen a couple examples using Three js via cljs->js interop. Is there a cleaner way to do it?

darwin09:11:13

I would recommend looking into react-three-fiber, It is doable, I ported a couple of their demos under cljs here: https://github.com/binaryage/cljs-react-three-fiber

defa09:11:43

I’m struggling using a JS library in context of a react-native app using shadow-cljs. The library is https://github.com/auth0/react-native-auth0. I can call into the library from pure JavaScript but translating these calls to ClojureScript does not work. Probably I’m missing something. Never had any trouble with using JS libraries from CLJS in this context. What makes the library different is that it exports a JS class and I suppose there is a difference regarding this when I call into the library?

🙌 1
defa09:11:32

The library:

export default class Auth0 {

  /**
   * Creates an instance of Auth0.
   * @param {Object} options your Auth0 application information
   * @param {String} options.domain your Auth0 domain
   * @param {String} options.clientId your Auth0 application client identifier
   *
   * @memberof Auth0
   */
  constructor(options = {}) {
    const { domain, clientId, ...extras } = options;
    this.auth = new Auth({baseUrl: domain, clientId, ...extras});
    this.webAuth = new WebAuth(this.auth);
    this.options = options;
  }
...
and this is the call in JS:
import Auth0 from 'react-native-auth0';
...
const credentials = require('./auth0-configuration');
const auth0 = new Auth0(credentials);
...
let webAuth = auth0.webAuth;
console.log('webAuth: ' + webAuth);
webAuth.authorize({scope: 'openid profile email'})
       .then(someCredentials => {...})
...
My attempt to call the same authorize function/method in CLJS:
(ns auth0.core
  (:require ["react-native-auth0" :as Auth0]))

(defn create [config]
  (new Auth0/default (clj->js config)))
(ns 
  (:require
    [auth0.core :as auth0]))
...
(def config {:clientId "...."
             :domain ""})

(def auth0 (auth0/create config))
(def webAuth (.-webAuth auth0))
(def authorize (.-authorize webAuth))
(authorize #js {:scope "openid"})
This fails with:
ERROR: TypeError: undefined is not an object (evaluating 'agent.newTransaction')
where agent is undefined.

thheller09:11:34

:as Auth0 is incorrect in this case

thheller09:11:47

oh wait nvm you are using /default

thheller09:11:24

just call the authorize maybe? (.authorize webAuth #js {:scope ...})

defa09:11:28

To be honest, I was poking around in the repl and was wondering why there is default but it returned some structure that appeared to be useful 🙈

thheller09:11:28

don't get the property of an object if you are supposed to just call ist

thheller09:11:09

webAuth.authorize({scope:...}) translates to (.authorize webAuth #js {:scope ...})

thheller09:11:35

the .- would be let authorize = webAuth.authorize; authorize(...) and that likely won't work either

defa09:11:46

I’m pretty sure I tried that at first hand… but obviously not since it seems to work now.

defa09:11:23

Thank you very much @U05224H0W.

defa09:11:51

I guess I have to reread the whole docs on using NPM.

thheller09:11:05

js interop can be a bit tricky at times but gets easier when you have done it a bunch 😛

Simon10:11:17

Anyone familiar with this issue?

Simon10:11:43

project still compiles and runs.

rberger17:11:58

I find when that happens, do a rm -r .shadow-cljs (the directory that starts with a . NOT shadow-cljs.edn)

rberger17:11:31

Something gets out of sync like new deps or node packages it seems.

thheller17:11:06

which shadow-cljs version do you use? this issue should have been fixed a while ago?

Simon11:11:30

Where am I missing a :key ? Warning: Every element in a seq should have a unique :key:

Simon11:11:00

The fix was that

(defn premium-block-blur [& children]
    ...)
Should be without & . Must have something to do with the fact that there are no other props. The error is quite misleading though. Hope this helps someone else stumbling upon the same issue 🙂

🙌 1
gratitude-thank-you 1
thheller17:11:25

except for the element in the for none of those should have a :key

JB Seo00:11:45

[:div {:key "children"} children] -> (-> [:div] (into children) . This behavior is little difference from those of React.

JB Seo00:11:36

For react, special prop children is not plain array, but a react component. For cljs, & children is just a sequence. That's why its elements should be 'key'ed or should be turn into vector.

Denis16:11:45

I am just tinkering with Krell. Can’t find right key for React renderItem. Any help appreciated, thanks.