This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-04
Channels
- # announcements (5)
- # beginners (124)
- # boot (43)
- # braveandtrue (8)
- # calva (1)
- # cider (44)
- # cljs-dev (1)
- # clojure (188)
- # clojure-canada (3)
- # clojure-germany (1)
- # clojure-italy (5)
- # clojure-nl (13)
- # clojure-russia (1)
- # clojure-spec (14)
- # clojure-uk (42)
- # clojurescript (94)
- # core-async (5)
- # cursive (5)
- # datomic (45)
- # duct (3)
- # emacs (6)
- # figwheel-main (93)
- # fulcro (22)
- # graphql (3)
- # hyperfiddle (1)
- # leiningen (3)
- # off-topic (1)
- # pedestal (1)
- # play-clj (1)
- # portkey (1)
- # re-frame (17)
- # reagent (71)
- # remote-jobs (2)
- # rum (3)
- # shadow-cljs (45)
- # spacemacs (17)
- # specter (18)
- # tools-deps (27)
- # unrepl (1)
- # vim (3)
Is there some way to turn clojurescript into javascript?
So that I can do the silly "give somebody an html file" deployment. 🙂
@anonypicard For shadow-cljs
shadow-cljs release your-app
For vanilla: https://clojurescript.org/guides/quick-start#production-builds@anonypicard Shadow-cljs has in my opinion lower threshold to get started. If you want to give it a go, this is largely the process:
yarn init
yarn add shadow-cljs
./node_modules/.bin/shadow-cljs init
Edit shadow-cljs.edn and add a build, {:app {:target :browser}}, for example
./node_modules/.bin/shadow-cljs release app
You might want to ln -s ./node_modules/.bin/shadow-cljs
for convenience.
More about builds here: https://shadow-cljs.github.io/docs/UsersGuide.html#_build_configuration@henrik you can also install shadow-cljs globally to skip the ln
part. ie. yarn global add shadow-cljs
We’re using shadow-cljs and now we’d like to have a CSS preprocessor (LESS or SASS, or convince me otherwise). Is it easiest to just install a preprocessor from npm? What’s a good way to integrate the CSS build into our lein build? We currently have shadow-cljs running via shadow-server
in dev and configured in uberjar build like this:
:prep-tasks ["compile"
["run" "-m" "shadow.cljs.devtools.cli" "release" "app"]]
@hannu.hartikainen I personally currently use node-sass
via the CLI https://github.com/sass/node-sass#command-line-interface
Ok, thanks. I guess I’ll consider separating the frontend and backend builds if that’s what experienced developers tend to do 🙂
you can create a (defn make-release [] (sh "node-sass" ...) (shadow/release :app))
fn and call that via ["run" "-m" "your.util/make-release"]
Ah, that’s a good tip. I knew running my own code as part of lein build must be possible, but never realized it’s that easy.
https://shadow-cljs.github.io/docs/UsersGuide.html#clj-run same way works in lein run
I also use node-sass
. I’ve just piled the commands into package.json
and run yarn release
.
Thanks. I’ll go with node-sass too.
I am thinking of writing a larger project in ClojureScript but I am not sure what libraries to use. Probably Reagent or Rum but I am not so sure about state management. Could Rum+DataScript be used instead of Reagent+re-frame or what stack would you pick?
I have no experience with Datascript, but as I checked it’s README. I’d go with re-frame + reagent. Otherwise you will end-up with recreating re-frame like framework IMO.
I didn’t created any Rum project, but as I see Rum+Citrus is a good choice, if you prefer Rum over Reagent.
State management is handled by Fulcro: http://book.fulcrologic.com/
I have done a small project in Reagent+re-frame, around 500 SLOC which doesn't say much since I am new to ClojureScript
For the webpack documentation, it says to create a build.edn file - I currently have all of my similar options in a project.clj. is that okay?
Oh I think I misread this. Are you recommending I move to a build.edn or that its fine to continue to have my project.clj handling that stuff?
there's something I'm not getting about metadata in clojurescript 😕 so, I have this component definition defined:
(defn ^{:cmp :button} button [name]
...)
and my header is designed to accept children as arguments, so I include a header with a button like this:
[cmp/header
^{:key "left button!"} [cmp/button "left button!"]]
but if I capture and inspect the meta of cmp/button at that point, it's nil
... shouldn't it be {:cmp :button}
because of the metadata I put in the definition?my advice is to use a regular key prop, rather than metadata, in reagent, much less confusing
hrm.. yeah, in this case I was actually hoping to use it to communicate something about the component to its parent components. They inject a BEM style class into the component. But it's all good. I can use a lookup from a registry atom to accomplish the same thing
basically, the reason I had ^{:cmp :button}
on the definition is so that buttons that are children of headers will have a class automatically added to them :header__button
. if that makes sense.
yeah I think there are simpler ways to accomplish this
I don't suppose there's any way that one can look up the symbol from an object? so, is there any way I can go
(some-function (first [cmp/button "a button!"])
=> 'cmp/button
hurgh... I can't actually figure out the "simpler" way to do this. I don't know what to use as a lookup key for a global registry, because there's nothing on the object that references its component. It's like I need to attach some kind of data that describes the object at a meta level :((
I have a clojure macro above that is called from clojurescript code. When the macro is pulled in clojurescript it is in "clojure" mode and the wrong test library gets pulled for clojurescript (`clojure.test` instead of cljs.test
). Wondering how I can get a cljc macro that knows it is being pulled for clojurescript purposes so can pull the correct testing library.
Hi guys, I am exploring extending the reader and writer. Extending the reader with tagged literals is simple enough,
(ns scratch
(:require [cljs.reader :as reader]))
(def ^:private reader-extensions {'atom atom})
(defn read-string
"Read a config from a string of edn. Refs may be denotied by tagging keywords
with #ig/ref."
([s]
(read-string {:eof nil} s))
([opts s]
(let [readers (merge reader-extensions (:readers opts {}))]
(reader/read-string (assoc opts :readers readers) s))))
(read-string "{:p #atom 1}")
;;=> {:p #object[cljs.core.Atom {:val 1}]}
Any pointers for docs, resources to learn how to extend the printer with custom serializers?
Thanks!@its.ramzi hiccup tags are fine!
@fj.abanses consider using transit-cljs
instead. extending the printer can only be done globally otherwise
@gon: so, when I do this it works: (defn make-table-from-string [n] (for [k n] (str "<h2> " k "</h2>") ) ) But when I do this, (defn make-table-from-string [n] (for [k n] (str [:h2 k ]) ) ) I get back: ("[:h2 \"0\"]" "[:h2 \"{\"]" "[:h2 \":\"]" "[:h2 \"i\"]" "[:h2 \"d\"]"
Any recommendations on debugging closure compiler :optimizations :advanced
logs? I’m getting some errors in the javascript console that are preventing my app from loading, but its pretty much impossible to figure out what is going on.
@fj.abanses If you make a custom deftype you can just define how the thing is printed and stringified right there.
And you can put as much info in there as necessary to rehydrate the object on the other side
@njj, - read https://clojurescript.org/guides/externs - turn on infer-externs - turn on pseudo-names (temporarily) - turn on warn-on-infer - study the warnings
also check these two PRs: https://github.com/pesterhazy/cljs-spa-example/pull/9/files and https://github.com/pesterhazy/cljs-spa-example/pull/10
usually fixing the problem is a matter of infer-externs
plus adding ^js
in the right places
Yes, the two are unrelated
np. you can also get fancy with it and reshape the printing of existing objects, as they flow through the system (using specify
). Even numbers. I just did that to play with a custom #float
reader that always prints as 0.0
instead of taking the js route and truncating trailing zeros and coercing to ints.
So, just do the specify
in the reader function for #float
, so that it prints the same (with a #float
) but also as an actual float.
np. They specify
thing is so you don't have to make a new deftype
if you don't want to, just alter semantics of existing types flowing through
@its.ramzi sounds like the hiccup forms must not be going through a hiccup interpreter. Maybe the hiccup is getting stringified or maybe your bypassing that interpretation somewhere
@john i do have (str all over the place, but that's because stuff worked with it and not without it.
@its.ramzi keep experimenting! 🙂
@john why would I be getting two alerts? When I do (for [k n]). The first alert has all the data in it, and the second alert has nil.
@its.ramzi you're turning the hiccup tags into strings by placing them inside str
.
Henrik, now I'm trying to get a Slickgrid on the page. I think I imported the dependent js files correctly, but I'm having a hard time actually rendering the grid.
@its.ramzi you can "drill in" to nested objects with extra for bindings, like: (take 10 (for [x (cycle [[[0 1 2] [3 4 5]]]) y x] y)) #_=> ([0 1 2] [3 4 5] [0 1 2] [3 4 5] [0 1 2] [3 4 5] [0 1 2] [3 4 5] [0 1 2] [3 4 5])
(defn change-dom [content] (-> js/document (.getElementById "some-div") (.-innerHTML) (set! (-> js/document (.getElementById "some-div") (.-value) [:h2 (str make-table-from-string content)])))))
You can't set hiccup forms on html nodes directly. They must go through a hiccup interpreter first.
I think it's something like (-> js/document (.getElementById "some-div") .-innerHTML (set! "content"))
View page source here: http://6pac.github.io/SlickGrid/examples/example-header-row.html How hard would it be to implement that in Clojurescript