This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-21
Channels
- # admin-announcements (14)
- # aws (27)
- # beginners (10)
- # boot (152)
- # cljsrn (3)
- # clojure (93)
- # clojure-hk (4)
- # clojure-russia (35)
- # clojure-switzerland (1)
- # clojurecup (1)
- # clojurescript (146)
- # core-async (23)
- # cursive (2)
- # devcards (1)
- # editors (1)
- # hoplon (28)
- # jobs-rus (4)
- # ldnclj (3)
- # leiningen (3)
- # luminus (2)
- # off-topic (4)
- # om (174)
- # re-frame (1)
- # slack-help (5)
Can goog.require
be set as the cljs.js/*load-fn*
for in-browser retrieving of dependencies?
I'm wondering what is the easiest way to make something like (ns cljs.user (:require [goog.string :as string]))
work in a bootstrapped CLJS environment in the browser
@pandeiro: I will need to solve the same problem as you because of https://github.com/ScalaConsultants/replumb (BTW have a look if you're thinking about bootstrapped repl)
what I came up so far is a simple way to pass your own load-fn from outside
@richiardiandrea: Neat, let me have a look.
at the moment nodejs can pass its own read-file-whatever
have a look here...https://github.com/ScalaConsultants/replumb/blob/master/repl-demo/node/cljs/nodejs_repl/core.cljs#L39
From looking at David's original clojurescript next blogpost, it seems like the load fn would have to resolve a namespace into a URL path
well, the protocol is, doesn't matter how, but call back weth :source
in it, or nil if you can't resolve
Right, I'm looking at this: https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/cljs_next/core.cljs#L147-L150
from what I gather get-file
returns the actual content taken from somewhere remote
(defn get-file [url cb]
(.send XhrIo url
(fn [e]
(cb (.. e -target getResponseText)))))
and you put it in the map as :source
it is the same as here https://github.com/ScalaConsultants/replumb/blob/master/src/cljs/replumb/target/nodejs.cljs#L30
yeah so this line here is sort of "cheating": https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/cljs_next/core.cljs#L145
but it could probably be turned into a fn that knows how to take a ns and generate a URL based on it
I do my cheating too :d -> https://github.com/ScalaConsultants/replumb/blob/master/src/cljs/replumb/target.cljs#L28
this makes me test require
without depending on the filesystem
basically it is loading the files he put in assets
through an ajax call to itself if I understand correctly
@richiardiandrea: Yep, indeed. I am still wondering if I can somehow use existing machinery (i.e., like how the browser REPL resolves (require 'foo)
) instead of having to hack together something to generate URLs... I feel like there's probably a better way than that...
I don't think you can avoid using a load-fn...it is part of the require
protocol
only if the required ns is already required load-fn is not called
Just out of curiosity, what do people think of as being the coolest / most popular ClojureScript projects?
For me: https://github.com/binaryage/cljs-devtools (and, it goes without saying, https://github.com/bhauman/lein-figwheel)
For me definitely https://github.com/bhauman/lein-figwheel
but also what is behind the React "movement", from Reagent to the latest Mike Fikes post 😄
@pandeiro: you need to solve the IO problem yourself, that’s what the *load-fn*
stuff is for. You can do whatever you like.
all the current REPLs have to define the semantics of goog.require
, not interested in supporting all these cases anymore
@dnolen: fair enough. what approach would you recommend then for the browser case? surely w/ the machinery that already exists, one shouldn't have to re-invent the wheel traversing dependency graph, etc? or am i missing something?
sure point taken, my use case is also development tooling, but i thought this could be re-used somehow from within a bootstrapped context (in the browser): https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/repl.cljc#L664-L681
@pandeiro: you can re-use but we’re (the core) not going to spend anymore time on bootstrapped
probably the best would be to port it to replumb now as I am trying to put there every REPL needs, so feel free to open a PR there and I will take a look
just so that we concentrate the effort in one point @pandeiro
@dnolen: with your blessing of course 😄
@richiardiandrea: no need for my blessing
so people can solve the numerous problems outside of ClojureScript mainline development
@dnolen: I wasn't asking for any code to be added to cljs, just orientation to figure out just what is missing to be able to cljs.js/eval-str (ns ...)
forms, that's all.
@pandeiro: the require machinery is there, you just need to plug IO for reading and returning the source, see here https://github.com/ScalaConsultants/replumb/blob/master/src/cljs/replumb/target/nodejs.cljs#L35-L44
we are plugging it in this way in replumb, and it can be made generic for browsers too
you pass in a read-file
that uses Chrome FS api and that should be it
@richiardiandrea: cool, i see the approach involved... for resolving stuff like cljsjs libs, you'd need to include their convention too (`*.inc.js`)
well that's true
it was just an example -> http://www.html5rocks.com/en/tutorials/file/filesystem
can be anything really
@shaunlebron's Parinfer in Replete: http://blog.fikesfarm.com/posts/2015-11-20-parinfer-in-replete.html
hum, wonder why I’m sometimes getting compilation error related to cached analysis files
file: #object[java.io.File 0x4a574aa3 "src/cljs/shopping_list/components/login.cljs"]
clojure.lang.ExceptionInfo: Map literal must contain an even number of forms
tag: :cljs/analysis-error
java.lang.RuntimeException: Map literal must contain an even number of forms
...
clojure.edn/read-string edn.clj: 46
clojure.edn/read-string edn.clj: 45
cljs.analyzer$analyze_file$fn__11176.invoke analyzer.cljc: 2857
...
clojure.core/swap! core.clj: 2238
cljs.analyzer$analyze_file.invoke analyzer.cljc: 2855
viesti: it is a long shot, but do you by chance use :global-vars
to set your *print-length*
?
at least the two edn cache files in components directory are readable by clojure.edn/read-string
give it a try, dump your compiled clojurescript, remove the *print-length*
setting, recompile.
was thinking that “bleh, I’ll just wipe out compilation directory”, but then though about opening slack
I’m working on devcards, and trying to make it support formatting clojurescript code. Unfortunately, when I pass it code that has data reader for #js
it barfs (No reader for tag #js
). I grepped the clojurescript source, but don’t see the “No reader” error message, so I’m assuming it is leveraging a macro to format stuff on the JVM. I tried putting a js
reader in data-readers.clj and that didn’t work….perhaps because data-readers isn’t supposed to use root level tags? Not sure….anyone have any hints for my next step? I don’t mind patching things, I am just having trouble finding the spot.
I found a helpful stack trace that got me down to the clojure reader code…so I’m teasing it apart now
would anybody have any idea why the externs aren't working here? https://github.com/yogthos/mojs-reagent
= function(b) {
console.log(mojs);
console.log(mojs.Tween);
return (new mojs.Tween(Yf(new pa(null ,3,[Ag, 999, Ig, 2E3, ig, mojs.Pa.Dc(b.getDOMNode())],null )))).Pc()
}
Is what bit me when I was experimenting with implementing Common JS module translation into the Clojurescript compiler
React creates a top-level object named React
and when I generated a Clojurescript module named React
it overwrote that top-level object
So if you have a namespace top.kek.core
you'll end up with a top level object that represents it.
in theory the compiler could be clever enough to track the namespaces defined and warn on collisions
how would I use a function like this in cljs:
function isEllipsisActive(e) {
return (e.offsetWidth < e.scrollWidth);
}
@tmtwd if you have an external function that expects a browser DOM node and you're using react then you have to run the function in the state where the node is mounted
In a figwheel repl, using leiningen checkout dependencies, is there a way to get the repl to pick up on the library changes without restarting the repl?
@mrg: what I usually do is adding checkouts/my-lib/src (or whatever lib needs) into cljsbuild’s source-paths temporarily