This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-05
Channels
- # announcements (3)
- # babashka (135)
- # beginners (82)
- # calva (55)
- # chlorine-clover (23)
- # cider (13)
- # clara (1)
- # clj-kondo (39)
- # cljs-dev (1)
- # cljsrn (2)
- # clojure (96)
- # clojure-france (3)
- # clojure-uk (24)
- # clojuredesign-podcast (1)
- # clojurescript (56)
- # conjure (73)
- # core-typed (1)
- # cursive (1)
- # datomic (10)
- # fulcro (57)
- # joker (4)
- # juxt (1)
- # malli (20)
- # meander (2)
- # off-topic (54)
- # re-frame (4)
- # reagent (3)
- # shadow-cljs (11)
- # spacemacs (6)
- # sql (26)
- # tools-deps (7)
Hello. I think this question can fit in here. Does anyone use calva for a shadow cljs project with reagent? I've been trying to run the repl for it for days with no success. It can start the app and Jack in but when I run even a (+ 1 1) it complains saying "are you sure you loaded your compiled files" or something like that. Does anyone know the fix for this?
I don't use commands to run the app, I just press F1 and look for the option Jack in, then I select shadow cljs and the project/app name
@UQQA22QFL well did you load your compiled files?
Looking at the link, this is exactly what I get as output when trying to eval something. " No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code "
I saw in some places that running a node repl fixes that, tried that but same output. According to that link, I have to run browser repl? I'm still a newbie with clojure, like 3 months using it maybe haha, so I am not entirely sure what has to be done to accomplish that. If it means opening the main page in browser I do that
builds {:app {:output-dir "/home/candy/landing/js" :asset-path "/js" :compiler-options {:optimizations :none :main landing.core :closure-warnings {:global-this :off} :closure-defines {re-frame.trace/trace-enabled? true day8.re-frame-10x.debug? true day8.re-frame.tracing.trace-enabled? true} :external-config {:devtools/config {:features-to-install [:formatters :hints] :fn-symbol "Fn" :print-config-overrides true}}} :target :browser :modules {:landing {:entries [landing.core]}} :devtools {:after-load landing.core/reload! :loader-mode :eval :http-root "/home/candy/assets/landing" :http-port 3333 :http-handler shadow.http.push-state/handle :preloads [devtools.preload day8.re-frame-10x.preload]}}
the page you load there must properly load the generated /home/candy/landing/js/landing.js
which it can't with that :http-root
unless you are routing that differently somehow
I get my normal page. It's just that I sync the generated js with a website (by using a separated git repo) and I don't want to upload the source code so I have a different folder for the compiled J's and source code.
My index is also in the new repo. Hmm. Does it have to be in same folder as source code? There's no way to keep it separated and make this compiled thing working?
of course its possible but the default assumption is that things are served by the local server
if it is not than all the host settings will be wrong and your client code won't be able to properly connect
do you mean this?
(let [c (js/document.getElementById "img-editing")
ctx (.getContext c "2d")
img (js/document.getElementById "segmented")]
(set! (.-onload img)
(do
(prn "drawing image")
(.beginPath ctx)
(.moveTo ctx 20 20)
(.lineTo ctx 20 100)
(.lineTo ctx 70 100)
(set! (.-strokeStyle ctx) "red")
(.stroke ctx)
(.drawImage ctx img 10 10)
)
)
)
@pshar10 Are you sure you changed the do to fn? Here is a js fiddle showing the problem it looks like you are running into. https://jsfiddle.net/k736teLn/
Yes I in fact did change it. This is what I'm running:
(let [c (js/document.getElementById "img-editing")
ctx (.getContext c "2d")
img (js/document.getElementById "segmented")]
(set! (.-onload img)
(fn []
(prn "drawing image")
(.beginPath ctx)
(.moveTo ctx 20 20)
(.lineTo ctx 20 100)
(.lineTo ctx 70 100)
(set! (.-strokeStyle ctx) "red")
(.stroke ctx)
(.drawImage ctx img 50 50)
)
)
;; (prn "image is " img)
;; (js/console.log "image is " img)
)
Nevermind! Found that http://clojuredocs.org/clojure.core/try
If the segmented img tag is already in the dom, maybe it already loaded before the onload listener is being set?
Ok so you're seeing the "drawing image" prn statement then? In this example https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage the image is within the canvas element. Is that the same for yours?
Doing this doesn't work either. Even when I plop the img tag within canvas without display:none, it doesn't show up. One would think that it should, right?
That's odd, does this codepen work for you? https://codepen.io/jayzawrotny/pen/poJXZwb
Ok, making sure it's not a browser issue. I updated it to include the stroke code which seems to be working. What is the size of the canvas and size of the image?
How do you use a Javascript dependency (as a Node module) from Clojurescript? Trying to use https://github.com/jgraph/mxgraph but I'm confused how. Tried adding [mxgraph 4.1.1]
in my project.clj
but it says it can't find it, tried adding it to package.json
but it doesn't seem to have any effect (I can put a nonexistent version in there and it doesn't complain). How would you normally bring in this module and require it into a namespace? Tried to follow https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules but it looks like it's not for lein, or?
Using shadow-cljs. I have a namespace with a require like this:
(:require [mxgraph :as mx])
and then I try to use it like:
(defn make-graph []
(mx/mxGraph. [:div]))
the error for that at runtime is: "TypeError: module$node_modules$mxgraph$javascript$dist$build.mxGraph is not a constructor"so maybe I do have the dependency and I'm using it wrong? I was trying to emulate this line from their tutorial:
var graph = new mxGraph(container);