This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-03
Channels
- # beginners (167)
- # boot (22)
- # chestnut (3)
- # cider (9)
- # clojure (107)
- # clojure-berlin (1)
- # clojure-greece (3)
- # clojure-italy (6)
- # clojure-losangeles (6)
- # clojure-russia (8)
- # clojure-spec (71)
- # clojure-uk (42)
- # clojurescript (186)
- # community-development (1)
- # core-async (12)
- # core-typed (1)
- # css (15)
- # cursive (29)
- # data-science (11)
- # datomic (8)
- # defnpodcast (28)
- # duct (2)
- # fulcro (169)
- # graphql (6)
- # hoplon (3)
- # jobs-discuss (1)
- # kekkonen (5)
- # leiningen (11)
- # lumo (7)
- # off-topic (14)
- # om (1)
- # other-languages (14)
- # portkey (7)
- # re-frame (27)
- # reagent (14)
- # remote-jobs (1)
- # ring-swagger (5)
- # rum (15)
- # shadow-cljs (52)
- # spacemacs (59)
- # specter (78)
- # test-check (3)
- # vim (9)
- # yada (23)
I think I read somewhere that you still have to use externs with :npm-deps
'd libraries...
it think some historical clojurescript transformed :npm-deps into :foreign-libs which wasn't part of :advanced optimizations, newly it seems to be according to that article
maybe you were reading some historical articles which are not correct anymore with latest clojurescript
I'm sorry I'm not familiar with this stuff, @anmonteiro should be the right person to ask 🙂
it won't work, your PrismicJS brought by :npm-deps is subject to advanced optimizations name mangling, original "plain" dev names no longer exist in your advanced build
you would have to take your PrismicJS out of :npm-deps and include it by hand in html script tag, then cljs-oops would be a great match, but you won't get :advanced optimizations for it
@madstap you have two options 1) use normal cljs interop with :npm-deps and latest clojurescript 2) use cljs-oops and manage PrismicJS outsite :npm-deps via html script tags
is it possible to require node modules in scripts meant for the browser? like for an electron app?
but target node adds the shebang stuff to the top of the script which makes the browser choke
Btw I'm not going to use it for resolving components. I looked up how re-com components organized, and that's just fine. I'm going to do it the same way
ns-resolve
is a function
what are you using ns-resolve
for?
ns-resolve is a little bit slower than using something directly, and using it to avoid having to use require is a bad idea (referencing prior conversation in this channel to infer that's what's going on here)
do you mean a <select>
element offering a list of timezones? seems trivial, just make its <option>
value
s have a format cljs-time understands
it’s not so trivial as it may seem to get that list of options. Joda Time specifies that is uses the Olson database (http://joda-time.sourceforge.net/timezones.html)
My question is: how can it be accessible throught cljs-time ? Entering manually the options is not a good solution (there was an update in the timezones in 2011), also +1 +2 is no good (daylight savings, +4.30 type timezones, etc)
there are updates to the TZs every year 🙂 A few (non-clojure) libraries I know are built out of http://www.iana.org/time-zones
I reckon that a server-side clojure or java library exists. You could build the list in compile-time leveraging the JVM libs
hmm yes, but a client side solution would be more conveniant than syncing with the server for those constants. maybe there’s a javascript library that fits with what joda is expecting
@melvoloskov Seems like you sorted things out, but FWIW, there is no ns-resolve
in ClojureScript.
I'm curious: Do ClojureScript devs consider using if-some
and when-some
over if-let
and when-let
when you know you only need a nil
check? In other words, for performance reasons, rather than a need to distinguish nil
and false
. Or is it generally still preferred to stick with the *-let
variants and rely on the Clojure definition of falsey. I could see an argument that using *-some
simply to avoid cljs.core.truth_
as being a premature optimization, and it being preferable to primarly only use *-some
when you need its semantics (not perf).
@leonoel Thanks—I suppose you would then use *-let
if you were using a bit of optional config from a map, and wanted a nil
result of get
to be semantically equivalent to an explicit false
tbh I never really got the point of conflating the idea of boolean with the idea of "being something"
It might be the case that *-let
is used out of habit, but if you scrutinize the needed semantics *-some
nearly always fits. In other words it might be hard to find a case where *-let
is actually what is needed (unless you are interacting with something that conflated the concepts, I suppose)
Hah. I think they also existed before my Clojure-birth, but I learned a lot of Clojure by reading code that was written before *-some
. Perhaps the truth is that *-let
could be use a lot less given *-some
.
Now, I'm really interested in a good example where *-let
is semantically exactly what is required 🙂
How do I turn
[:a (js/Promise. (fn [resolve] (resolve :b))) (js/Promise. (fn [resolve] (resolve :c))) :d]
into
[:a :b :c d]
?Promise.all(["a", "b", Promise.resolve("c")]).then(arr => console.log(arr))
you can do this to get a flat array inside a Promise@qqq, clojurescript!
clojurescript doesn't have blocking deref
I get a smiley face in my promise??
I have a vector with some elements being promises; I want to do something the upshot of which is that I get the same vector, but with the promises replace by their results
at least with native promises: if you use another promise library, they may have public state
yeah I'm using native promises
I'll end up doing something based on Promise.all - it doesn't have to be synchronous
I can't figure out how to check is a value is a promise
well I need to walk the vector to extract all slots that need to be replaced
interesting
@sundarj ah sorry I missed the thread
there's core.async but that's a different model than promises
@zignd funcool/promesa has await on bluebird promises: http://funcool.github.io/promesa/latest/#async-await-syntax
@mccraigmccraig this alet
macro seems very useful and would probably help in that case @pesterhazy showed
i've not used alet
from funcool/promesa - i have used alet
from funcool/cats, which is similar but more general - it's awesome
@zignd, @sundarj, came up with this snippet for resolving deeply nested data structrures:
(defn deep-resolve [xs]
(let [ks (->> xs
(tree-seq coll? seq)
(filter #(.-then %)))
p (js/Promise.all (into-array ks))]
(.then p
(fn [vs]
(let [m (zipmap ks vs)]
(walk/postwalk #(if (contains? m %)
(m %)
%) xs))))))
@sundarj wouldn't that make everything into a promise?
hmm then the idea would be to postwalk twice, but only to transform the leaf values
it would, yes. but it also means you don't lose the plain values, which i personally wouldn't want
think of a structure like
{:foo [(js/Promise.resolve 1) 2]}
it should work with a deeply nested structure like this as well
I agree that filtering by .-then
is weird
it is how things like http://npm.im/is-promise also detect promises to be fair
but i figure if you don't care whether something is a plain value or a promise then Promise.resolve
is the way to go
@souenzzo in clojure promise-like things (e.g. clojure.core/promise
and manifold/deferred
) tend to support deref
, but not in cljs - deref
is blocking and so not a good fit for js execution model
@mccraigmccraig promises now can deref'ed
by await x = myPromise()
oh i see, that's not really a deref though - that's like alet
or async/await
in funcool/promesa http://funcool.github.io/promesa/latest/#async-await-syntax
cljsjs has small amount of info about creating externs, https://github.com/cljsjs/packages/wiki/Creating-Externs
although, the best case scenario is if the library you want is already available in cljsjs
the externs for react-grid-layout
were created using http://jmmk.github.io/javascript-externs-generator/
not sure how fully featured that option is, but it can hopefully help get you started
I've use that, but I can't get rid of the error:
$("#fluxo").treetable();
VM7812:1 Uncaught TypeError: $(...).treetable is not a function
at <anonymous>:1:13
I'm trying to create a externs for the treetable jquery plugin
that’s an example of externs for another jquery plugin
this is the code: https://github.com/ludo/jquery-treetable/blob/master/jquery.treetable.js
but I can't figure out the name for the object
I've tried jQuery
, but doesn't work
is jQuery
being included in the javascript somewhere on the page?
and being loaded before the code that is using it?
how are you referencing jquery from your cljs code?
i'm not referencing from cljs yet.. just trying in browser console
if it’s not working in the browser console, then problem probably isn’t with the externs
as that’s a closure compiler thing
works in browser console if I remove my cljs script tag
Once my cljs script is loaded, doesn't work anymore
do you know how i can check if the externs configuration are been loaded?
this is how is my project.clj:
:cljsbuild {:builds
[{:id "dev"
:source-paths ["src"]
;; the presence of a :figwheel configuration here
;; will cause figwheel to inject the figwheel client
;; into your build
:figwheel {:on-jsload "sghi-dashboards.core/on-js-reload"
;; :open-urls will pop open your application
;; in the default browser once Figwheel has
;; started and complied your application.
;; Comment this out once it no longer serves you.
:open-urls [""]}
:compiler {:main sghi-dashboards.core
:asset-path "js/out"
:output-to "resources/sghi/js/sghi_dashboards.js"
:output-dir "resources/sghi/js/out"
:source-map-timestamp true
;; To console.log CLJS data-structures make sure you enable devtools in Chrome
;;
:preloads [devtools.preload]
:optimizations :none
:externs ["resources/externs/treetable.ext.js"]}}
you should be able to just look at the output file
resources/sghi/js/sghi_dashboards.js
what I should look for?
@gleisonsilva have you considered using https://github.com/binaryage/cljs-oops?
when running with figwheel, my resources/sghi/js/sghi_dashboards.js
just have the google closure thing
you have optimizations set to :none
@darwin I didn't knew that
often, without optimizations, you don’t even an externs file
@smith.adriane yes... i'm trying everything now...
so I would look at the output and try to figure out why jQuery is no longer there
when using figwheel (dev build), should I find the references for treetable below out
folder?
the references for treetable won’t show up in out folder
the closure compiler uses the externs file during optimization to prevent from renaming variables
for eg, if you had a method name that was really long, the closure compiler can rename it in the outputfile js file to produce a smaller output
so, if i'm running the dev build, without optimizations, this would not be needed, right?
I don’t think you need an externs file if you’re not compiling with optimizations on
worked! I've just moved the references of .js files after my own .js (.cljs file)
this works:
<script src="js/sghi_dashboards.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-treetable/3.2.0/jquery.treetable.js" type="text/javascript"></script>
if the reverse order, don't
weird, are you including jquery as one of your cljs dependencies?
maybe indirect
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.229"]
[org.clojure/core.async "0.2.391"
:exclusions [org.clojure/tools.reader]]
[cljs-ajax "0.5.8"]
[reagent "0.6.0"]
;;[com.cognitect/transit-cljs "0.8.239"]
[cljsjs/d3 "3.5.5-0"]
[cljsjs/c3 "0.4.11-0"]
[cljsjs/bootstrap "3.3.6-1"]
[lein-doo "0.1.6"]
got it
i might try keeping the same script tag order while commenting out the jquery
script tag
otherwise, you might be including two jquery’s
ok. i will
thank you very much!
you can also do `lein deps 🎄
lein deps :tree
i will do this now
[cljsjs/bootstrap "3.3.6-1"]
[cljsjs/jquery "1.9.1-0"]
and if you ever get the externs figured out for treetable, you can send a pull request to the cljsjs folks to save others the trouble. they’re pretty friendly
is the order of directories in source-paths
honored, such that in this example, "src" will be compiled (and evaluated) first, followed by the second env ns? :source-paths ["src" "env/prod/cljs"]
i'm just curious how the reagent-frontend-template "knows" to run the env/prod/cljs ns first, since there is no main
referrign to this: https://github.com/reagent-project/reagent-frontend-template/blob/master/resources/leiningen/new/reagent_frontend/project.clj#L42
I’d look for what the script tag in the html loads, you can work back from that
for example I don’t use main for that - I have a script tag that ensures my js is loaded, and another that invokes my top level function with inline js (providing args as apropriate to the client)
the reagent template has namespaces in dev/ and prod/ which actually load the main app. the dev setup has :main, but the prod does not, yet the prod namespaces still calls the core entry function, so was curious how that works
there’s no other tag that invokes something defined by app.js? if not, there must be some automatic magic in the reagent-frontend-template code
the cljs file in prod/ just calls the init fn on toplevel
toplevel code from all ns is evaluated when loading the app in browser
both dev and prod call (core/init!) but the dev setup uses :main to do this, while prod does not. I was curious the reason for this.
in some cases
for eg, if you had a function like save!
you could implement in cljs via a jquery
ajax call
and in clojure by writing to a database