This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-30
Channels
- # aws (5)
- # aws-lambda (2)
- # beginners (29)
- # boot (5)
- # cider (3)
- # cljs-dev (3)
- # cljsjs (2)
- # clojure (112)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-italy (9)
- # clojure-nl (2)
- # clojure-russia (5)
- # clojure-spec (49)
- # clojure-uk (41)
- # clojurescript (157)
- # core-logic (5)
- # crypto (1)
- # cursive (12)
- # data-science (38)
- # datomic (31)
- # emacs (3)
- # events (2)
- # garden (3)
- # graphql (10)
- # immutant (4)
- # jobs (3)
- # juxt (5)
- # klipse (1)
- # luminus (3)
- # off-topic (40)
- # om (1)
- # onyx (39)
- # other-languages (7)
- # protorepl (3)
- # re-frame (40)
- # reagent (60)
- # ring (8)
- # ring-swagger (14)
- # shadow-cljs (159)
- # spacemacs (1)
- # specter (6)
- # uncomplicate (3)
- # yada (2)
I'm trying to use cljs as part of an existing application. The existing app uses requirejs as the basis for an elaborate frontend system. If I load the main.js via a script tag in the html page head I get
core.cljs?rel=1509349831285:15 Uncaught ReferenceError: ReactDOM is not defined
at example_demo$core$render_BANG_ (core.cljs?rel=1509349831285:15)
at core.cljs?rel=1509349831285:24
I believe the issue might be that requirejs loads all dependencies into a non-global scope, so js/React
does not work.
The file react.inc.js and react-dom.inc.js are being loaded according to the network tab.@cmal Thanks for getting back to me. I've managed to load the code using the requirejs config shims to declare the dependencies between cljs_deps.js, cljs_deps.js and goog/base.js
I am trying to get a nice development setup running so I don't want to use any optimizations.
what ever you use, you should extern the React and ReactDOM if you use cljsjs, otherwise they will get compiled away. I am not sure whether this is your problem.
I'm using react and react-dom deps from cljsjs so I think the externs should be taken care of.
It works fine if I load the main.js as the sole JS application on a page (outside of the existing legacy app)
If you can load the advanced compiled main.js
, that is not the problem which I refer to.
At the moment I've thrown away all the source to debug another issue I've run into, which I think is related to the rendering system of the existing app. If I execute even one line of Cljs the <body>
tag of the page dissapears.
Just a namespace is enough to make it happen.
I don't know whether the main.js
can be used in require.js
, I just avoid using it. The shadow-cljs
author @thheller is an expert in this aspect.
@thheller I only need to run my app on a page where other require.js code is present, I don't want to use AMD/require.js modules from within cljs. Is that still a problem with shadow-cljs?
@vinai Do you have a demo project? maybe I have some time right now and I can test for this.
@cmal The app I wat to sneak ClojureScript into is based on http://github.com/magento/magento2/
I also want to know 😄 I am developing in a require.js
project using cljs to compile new files, too.
I really dislike the frontend rendering system so I would LOVE to get cljs to work in there
@cmal Thanks for you offer, I don't have a small demo project available, because the demo project is this large monster.
I'm loading the cljs with this code into the page:
<script>
var CLOSURE_UNCOMPILED_DEFINES = {};
var CLOSURE_NO_DEPS = true;
require(['/out/compiled/cljs_deps.js'], function () {
goog.require("devtools.preload");
goog.require("process.env");
goog.require("example_demo.core");
});
</script>
I'm triggering the loading the goog dependencies with this shim config:
var config = {
shim: {
'/out/compiled/goog/deps.js': {
deps: ['/out/compiled/goog/base.js']
},
'/out/compiled/cljs_deps.js': {
deps: ['/out/compiled/goog/deps.js']
}
}
};
If I add a :require [cljsjs.react]
to the ns then react gets loaded but js/React isn't defined.
@thheller I am working on a project in which I want to compile some cljs to npm mobule and include in require.js
. Can this work? I can give you my code later if you have time to look.
@cmal sure, just ping me in #shadow-cljs. can’t really say if it can work without seeing the js
require(['/out/compiled/cljs_deps.js'], function () {
goog.require("devtools.preload");
goog.require("process.env");
goog.require("example_demo.core");
});
http://magento2-demo.nexcess.net/collections/yoga-new.html this is a magento demo?
I'm actually trying this on a stock magento installation with that sample data in it to first tackle Magento integration, and then integration with all the custom code in a second step.
(ns example-demo.core
(:require [sablono.core :as sab]
[cljsjs.react]
[cljsjs.react.dom]))
(.log js/console "CLJS init")
(defn render! []
(.render js/ReactDOM
(sab/html [:div
[:h1 "Magento integration done"]])
(.getElementById js/document "demo")))
(render!)
This is what I'm trying to get to work.That would require modifying the core code of the existing app which really wants to load requirejs first. Still, might fall back to that.
@thheller That is a good idea. I just don't know how to create npm modules from shadow-cljs
. I will just try to include the compiled js file into a separate script tag.
If I have to modify the platform code to load the cljs main.js first I think I might not get my code into the sytem 🙂
BTW, @thheller will goog-compiler
compile out all the non-related code other than those related to the ^:export
function?
if you use :npm-modules
you can specify :entries [some.ns ...]
so it doesn’t include everything in your source path
Hello guys! This is the first time i tried making google closure externs and using them with :advanced compilation. My extern javascript file has a constructor called CrossStorageClient with some prototype functions. My ext.js looks like this: var CrossStorageClient = { "_generateUUID": function () {}, "_getOrigin": function () {}, }; CrossStorageClient.prototype = { "clear": function () {}, "close": function () {}, ... etc I achieved that now closure doesnt rename any functions in my extern js in advanced mode, I can def (def storage (new js/CrossStorageClient "http://...")) but then if i tries to call (.close storage) closure renames storage and .close too Sorry as i said im pretty noob to the closure compiler. What is the point here? any help is appreciated my fellow Clojurians!
/** @constructor */
var CrossStorageClient = function(url) {};
CrossStorageClient.prototype.close;
It works! Thank you! 🎉
quick follow up from earlier - the only way I managed to get things to work is indeed by loading main.js first, before requirejs is included.
considering the following trend graph from google: https://trends.google.com/trends/explore?date=today%205-y&q=vue.js,react.js,angular.js it seems that vue is gaining popularity as compared to react. I'm new to clojurescript, but it seems that most of the buzz in the cljs community is still about react integrations (om (next), reagent, re-frame) and the community seems eerily quiet about vue (or I'm just hanging out in the wrong rooms). Is this just because vue is newer or is there some fundamental reason it doesn't play well with cljs or is otherwise not a good option?
see https://clojurians-log.clojureverse.org/clojurescript/2017-08-19.html#inst-2017-08-19T17:12:05.000035Z for one instance of a Vue discussion
searching for Vue here https://clojurians-log.clojureverse.org returns more stuff
@U61HA86AG thank you for the pointers! seems there are mutability concerns with vue...I received some comments from my .Net friends that react bound the ui too tightly to the data model, but I'm not really sure I see that with om.next (admittedly with my limited understanding of om.next)
it was never about react's popularity first version of om was written before the hype train had started there are technical reasons for using react
thanks for the answer, like I said I'm new to clojurescript so I'm not trying to critique the status quo, I think the options in clojurescript land look quite promising from where I stand...but I also feel humbled by the number of frameworks involved and my lack of knowledge. Would you care to elaborate on any of the technical reasons to go with react vs vue?
Not @U050C3W27, but the primary reason is that React very nicely maps to functional programming model. For the most part, outputs are just functions of their inputs, which plays well with Clojurescript. Vue offers that, but it also offers things like two-way bindings, which don’t play as well.
^ this
@U4VDXB2TU just give it some time. learn the basics and clojure way of doing things and you'll get it
I'd add that there probably isn't that much to gain from using Vue over React, from a ClojureScript perspective. All that React really gives us is a virtual dom implementation, most of the other stuff like how you do templating and structure components is defined by the ClojureScript libs, React is just a low level API they build on, so a lot of what Vue does different isn't that relevant here. Given that this is a small ecosystem with limited manpower, people probably prefer to focus their efforts instead of going after the hype of the day. React isn't going away, after all.
@plexus thanks for elaborating. I'd write the same if I had time 🙂
@U050C3W27 I don't have an issue with the clojure way, I'm on a fairly friendly basis with clojure, just new to cljs
I have a question regarding figwheel. I have a small example app which clojurescript only consists of a run function printing "Hello world" to the console. I added figwheen and expected, after I changed the "Hello World" string to something else to have it change on the client as well when running the run
function through the developer console. It didn't work. Am I missing something? The full repo (as said, very small) can be found here: https://github.com/elevantorg/beta.elevant.org/tree/2c4aa3cc9029e1f0af9a924bbd7cfbb4b2a764be
The websocket and everything is working, as changing css is pushed to the client and applied automatically
If you wanted to profile and speed up a Clojurescript (Figwheel) build, where would you start?
We have a dev setup with Figwheel, and it's taking 5 seconds for each change to be compiled and reloaded, which is a lot slower than we expected...
there is an example here: https://github.com/randomlurker/reframe-auth0
but when I try to code the lock with dynamic data I cannot seem to attach the on
listener
I’m sure I am missing something dumb as I’ve been bashing on it for an hour or so and cannot work it out 😕
@raymcdermott I also don't see it... are you sure these are the only differences?
You may try these tweaks in project.clj
:
:cljsbuild {:builds [{:id "dev"
:compiler {
; speeds up compilation:
:recompile-dependents false ; this makes hot reloads noticably faster! but in very rare cases can cause stale code bugs?
:parallel-build true ; mostly speeds up initial compilation
...
@raymcdermott The only thing I can think of (a stretch, and a guess), is that the lock
object has nothing preventing it from being GC'd in your second example.
thanks @metametadata, but we already have both of those flags set
@mfikes the problem I have is that I don’t want to def the lock - it needs to be created based on some config I obtain from the server side
(it does this when it works too … but in that case some state has been created in the DB from the callback)
I was able to pin my problem (see above) further down: figwheel does not pick up my changes. Do I have to run lein cljsbuild auto
in parallel? I was under the impression figwheel does this automatically!
in my experience figwheel reloads files when they change, but things like switching git branches or running a clean and compile in another window can get it confused about the file state (it can end up watching a file that was deleted, and not see the new file with the same name for example)
but even when that happens, running clean-build then build-once will typically get it back on track without a full restart
In my case, nothing seems to work. As said, css watcher works fine but cljs doesn't. Running (build-once) in the repl does change the files in resources/public/js/out
but does not push it to the browser
I'm wondering if there is an issue with my setup, serving the static assets through compojure handlers. The figwheel docs do say "This will start a server at http://localhost:3449 with your resources being served via the compojure resources ring handler."
Any recommendations on how to mock web responses? I see ring.mock suggested but can only find ways to mock requests. So far my search has me leaning to https://github.com/johanhaleby/stub-http.
Is it just me, or does cljs.pprint/cl-format
behave differently from clojure.pprint/cl-format
?
(doseq [x [1 2 3]]
(cljs.pprint/cl-format true "~A" x))
1
2
3
(doseq [x [1 2 3 4 5]]
(clojure.pprint/cl-format true "~A" x))
123nil
clojure: format = javascript https://github.com/madogiwa/format4js