Fork me on GitHub
#clojurescript
<
2018-02-25
>
mfikes01:02:30

The new cljs.main ClojureScript capability is very solid at this point, but could use your help in finding bugs prior to release! It is real easy to try it out with a single command, as detailed in this gist: https://gist.github.com/mfikes/2511a401ce92ca5315fdd2907ae18081 I really recommend giving it a spin—this is really going to make trivial to get up and running with ClojureScript for a lot of use cases!

zentrope02:02:52

@mfikes Is there a documentation page describing what it is?

mfikes02:02:02

Not yet. But, in short, it is the ClojureScript analog of clojure.main, which has been available forever and lets you run Clojure files, or start a REPL with -r, or evaluate an expression with -e, or run a namespace with -m. This same capability exists in the new clj / clojure tool. What's it good for? Well, if you want to fire up a REPL, it is now trivial. But you can also use it to, say, run tests in a ClojureScript test namespace, or even run a browser REPL and have it automatically compile your code as you view the results in a browser. (Much of the Quick Start will likely be updated to work in terms of it.)

mfikes02:02:48

For a lot of simple use cases, there will no longer be any setup.

zentrope02:02:03

Yes, it sounds pretty good. I was thinking there’s be a http://clojure.org/guide or something similar.

mfikes02:02:24

Yeah, I would expect documentation like that in the end.

mfikes02:02:47

I guess the Clojure guide is https://clojure.org/reference/repl_and_main and perhaps there will be a ClojureScript equivalent.

ackerleytng07:02:11

i'm using the google maps api and when using :optimizations :advanced I get this Uncaught TypeError: Cannot read property 'sf' of undefined. The offending line of compiled javascript is return new google.md.sf(a,b) I've already included [cljsjs/google-maps "3.18-1"] as a dependency. how do i check that the dependency is being used?

ackerleytng07:02:46

tried to generate a source map but got

Exception in thread "main" java.lang.AssertionError: Assert failed: :output-dir "target/cljsbuild-compiler-1" must specify a directory in :output-to's parent "/Users/ackerleytng/Documents/moocs/clojure/gowherene/target/cljs-output/public/js" if optimization setting applied

ackerleytng07:02:11

oops. to fix the source-map issue, i should have added something like :output-dir "resources/public/js/compiled"

ackerleytng07:02:05

random comment. I am SO impressed by source maps.

leira08:02:14

Is it possible to use re-frame without reagent/react back end? I mean, use it as general application frame work, but not render into webpages? Or is there a similar library for general application?

ackerleytng09:02:57

if i specify an externs file, is it appended to the rest of the externs that came with the libraries?

mikerod14:02:35

@leira well I believe it is coupled with reagent/react currently. There was an issue in GitHub before about being able to use an alternative backend and I think a sample project was made called re-Frankenstein or something. Not sure much more on that. However there is also re-natal that could let you use re-frame with react native to target native apps instead of web. https://github.com/drapanjanas/re-natal/blob/master/README.md Not sure what you are looking for more specifically though.

tianshu16:02:57

is it possible to destructing js object?

noisesmith16:02:41

@doglooksgood - you can do a few useful things with goog.object which comes by default https://google.github.io/closure-library/api/goog.object.html

noisesmith16:02:34

but not keys destructuring like we'd do with a hash-map, no

tianshu16:02:29

I think interop in clojurescript is used more often than in clojure.

noisesmith16:02:17

I use it pretty frequently in both - then again I'm the one most comfortable with interop in my team so I get those tasks 😄

tianshu16:02:05

(defn- render-item [x]
  (r/as-element
   [view {:style {:background-color "yellow"}}
    [text (.. x -item -text)]]))   ;; <------------------

(defn app-root []
  (let [greeting (subscribe [:get-greeting])]
    (fn []
      [view {:style {:flex-direction "column"
                     :margin 40
                     :flex 1
                     :align-items "center"}}
       [flat-list {:data [{:text "a"}  ;; <---------------
                          {:text "b"}
                          {:text "c"}
                          {:text "d"}]
                   :key-extractor (fn [item index] index)
                   :style {:width 100
                           :height 10}
                   :render-item render-item}]])))
what do you think about this?

darwin16:02:02

@doglooksgood yes, it is possible by extending js objects to implement ILookup, see this code: https://stackoverflow.com/a/16904181

darwin16:02:32

but it is not recommended to do unless you have full control over your js env and you know what you are doing 🙂

tianshu16:02:54

a good solution for me maybe, thanks!

darwin16:02:13

instead of aget you should be using unsafe-get these days (a side note)

noisesmith16:02:17

isn't aget for object lookup discouraged now too? (that's part of why I linked to goog.object)

noisesmith16:02:40

goog.object/get has the required not-found behavior of ILookup -lookup already

darwin17:02:43

correct, goog.object/get is a better option, I just wanted to point out that the code in that SO answer is a bit outdated 🙂

erwinrooijakkers19:02:48

Is there a way to create a cljsjs package of a JavaScript file that uses a WebAssembly (.wasm) file?

mfikes23:02:23

cljs.main can now synthetically generate index.html making browser-based REPL startup effortless. To see for yourself, try this one liner

clj -Sdeps '{:deps {github-mfikes/chambered {:git/url "" :sha "094c4b943e25dfdaa0c0886fa2bdbf537ec0316a"}}}' -m cljs.main -re browser -c chambered.core -r
and after the REPL starts, if it doesn’t automatically, go to http://localhost:9000 in your browser