Fork me on GitHub
#shadow-cljs
<
2021-01-27
>
tomrbowden07:01:25

has anyone managed to get Klipse working on Shadow-CLJS? I’m having one heck of a time trying to get it to build.

[:app] Build failure:
The required namespace "cljsjs.codemirror.addon.edit.matchbrackets" is not available, it was required by "klipse/ui/editors/editor.cljs".
I have already added codemirror via npm install codemirror, so I’m stuck…

tomrbowden10:01:32

Thanks for your reply @thheller. I’ve added the file src/main/cljsjs/codemirror.cljs file to my project, with this code inside:

(ns cljsjs.codemirror
  (:require ["codemirror" :as cm]))

(js/goog.exportSymbol "CodeMirror" cm)
However, I still get the build failure:
The required namespace "cljsjs.codemirror.addon.edit.matchbrackets" is not available, it was required by "klipse/ui/editors/editor.cljs".
I must be doing something silly — I just can’t work out what it is…

thheller10:01:21

well you added cljsjs.codemirror not cljsjs.codemirror.addon.edit.matchbrackets

thheller10:01:05

thats a different ns and different require

thheller10:01:32

you can look at how that cljsjs package is created to find out what require that would be

thheller10:01:54

may just be "codemirror/addon/edit/matchbrackets" but I'm not sure

tomrbowden11:01:09

Sorry about this, but I am still confused. I have also added the file src/main/cljsjs/codemirror/addon/edit/matchbrackets.cljs file to my project:

(ns cljsjs.codemirror.addon.edit.matchbrackets
  (:require ["codemirror.addon.edit.matchbrackets" :as cmaem]))

(js/goog.exportSymbol "CodeMirrorAddonEditMatchbrackets" cmaem)
Now I get the build error:
[:app] Build failure:
The required JS dependency "codemirror.addon.edit.matchbrackets" is not available, it was required by "cljsjs/codemirror/addon/edit/matchbrackets.cljs".

Dependency Trace:
	clojsandbox/app/core.cljs
	klipse/run/plugin/plugin.cljs
	klipse/plugin.cljs
	klipse/klipse_editors.cljs
	klipse/ui/editors/common.cljs
	klipse/ui/editors/editor.cljs
	cljsjs/codemirror/addon/edit/matchbrackets.cljs

thheller11:01:07

please check what I said in my last message 😛

thheller11:01:21

the require string does not always match the cljsjs name exaclty

thheller11:01:57

so at the very least it requires / instead of .. you can find the correct path by going into node_modules/codemirror and finding the correct folder or matching .js file for the above

thheller11:01:20

so either node_modules/codemirror/addon/edit/matchbrackets.js or node_modules/codemirror/addon/edit/matchbrackets as a folder

tomrbowden11:01:33

Doh! Silly mistake. I think I need to get some rest, thanks for your patience @thheller

witek12:01:31

Hello. I have included the npm module qrious into my package.json. How do I require it in my namespace and call the constructor new QRious()? -> https://www.cssscript.com/pure-javascript-qr-code-generator-qrious/ I have tried ["qrious" :as qrious] but js/QRious is not defined. qrious seams to be a function, but calling it throws Cannot read property 'bind' of undefined .

thheller12:01:59

@witek in general you NEVER use js/ for anything that you imported via require in the ns. you use the :as name directly

thheller12:01:34

so probably just (qrious. ...)

witek13:01:15

(qrious. ...) throws Uncaught Error: Invalid option: __reactInternalInstance$uiqex7uo9w at Nevis.extend.exists._set (qrious.js:1924). When using qrious in Vanilla JS, I have to call the QRious() constructor, which is defined globally when including the qrious.js via <script>. Don't I have to mention this QRious constructor somehow? Perhaps you have a hint for me after having a look at qrious.js: https://github.com/neocotic/qrious/blob/master/dist/qrious.js

Michaël Salihi14:01:49

Hi @witek, did you tried to use qrious in vanilla JS with require like const qrious = require('qrious')? It works? The doc does not mention this method.

Michaël Salihi14:01:09

If yes so as mentionned thheller, require the lib in your CLJS namespace like that:

(ns your-namepace
  (:require ["qrious" :as qrious]))
Then you could interop: (def qr (qrious. #js {:element (.getElementById js/document "qr"), :value "Custom value"})) > Don't I have to mention this QRious constructor somehow? Note the dot after QRious, this is a sugar syntax for construct new Object...equivalent to (def qr (new qrious #js {:element (.getElementById js/document "qr"), :value "Custom value"})) Refresh your page and it should works.

👍 3
thheller16:01:39

@witek without a full code snippet for what you are doing we cannot help much. the constructor appears to be called properly, just with an option it didn't expect, since it seems to get to this part https://github.com/neocotic/qrious/blob/master/dist/qrious.js#L1923

benny19:01:38

trying to use rechart, but it’s failing to build with the following error. any ideas? > Closure compilation failed with 2 errors > --- node_modules/d3-array/dist/d3-array.js:271 > This code cannot be converted from ES6. extending native class: Map > --- node_modules/d3-array/dist/d3-array.js:291 > This code cannot be converted from ES6. extending native class: Set

thheller19:01:49

@benny you need to up your :compiler-options {:output-feature-set :es6} if there is code that can't be transpiled

benny20:01:42

that did it! thanks @thheller

jaime21:01:46

Hi all, how to do the hot-reload trick in react-native, similar to below example with react-dom...

(defn ^:dev/after-load start []
  (reagent/render [ui {:x (js/Date.now)}] dom-root)) 
Here is the entry point for react-native, it accepts a function that returns react component
(react-native/AppRegistry.registerComponent "myApp" #(reagent/reactify-component root))
EDIT: I've tried below which I've found thru googling but does not work. Though I don't really understand the theory behind to be honest 😅
(def root-version (atom 0))
(defn reloadable-root []
  @root-version
  (r/reactify-component root))

(defn start []
  (rn/AppRegistry.registerComponent "myApp" reloadable-root))

(defn ^:dev/after-load after-load []
  (js/console.log "after load...")
  (swap! root-version inc)
  (start))

thheller22:01:29

or copy what that does if you want to roll your own

thheller22:01:58

I can tell that for you the issue is that your are deref'ing the @root-version outside of a scope where reagent looks for it

👍 3
jaime22:01:41

@thheller Awesome! ❤️ Thanks for the link. I will try that trick. Btw, IIRC you also use cursive and intellij? How do you manage to switch between repl? One thing I noticed is that for running (shadow.cljs.devtools.api/watch-compile-all!), you need to be in the CLJ repl. But for evaluating cljs, you need to be in the CLJS repl. How do you manage to compile/reload while making changes?

thheller22:01:52

I never use (shadow.cljs.devtools.api/watch-compile-all!) so I rarely have a reason to be in a CLJS repl when working on CLJS

jaime07:01:35

I'd be interested to know about your workflow when working with web apps. Would you mind sharing? 😄 Do you just enable the autobuild when watching file changes?

thheller09:01:03

yes, just the regular shadow-cljs watch app. or rather nowadays just shadow-cljs server and start the watch from the UI

thheller09:01:55

heavily using tap> with Inspect but actually very little REPL for CLJS

jaime10:01:35

Thanks for sharing. Will try experiment with that workflow

jaime20:01:34

Looks like this is the tap> workflow you've mentioned? https://clojureverse.org/t/introducing-shadow-cljs-inspect/5012 Not sure what is the difference with tap> and sending forms to repl. But somehow I'm excited to acquire new super powers!! :star-struck:

thheller21:01:27

tap sends it to the UI. the UI isn't otherwise integrated into the REPL for now.

thheller21:01:54

just open the ui at http://localhost:9630/inspect-latest and tap something in the REPL

thheller21:01:08

(assuming you use a somewhat recent version)

jaime21:01:13

When I select view as edn , it shows as the var

jaime21:01:28

I already changed my keymap from send to repl to (tap> ~selected) repl command 😉

thheller22:01:04

when I do some CLJ stuff I just open a second connection