This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-03
Channels
- # arachne (31)
- # aws (9)
- # bangalore-clj (7)
- # beginners (46)
- # boot (18)
- # cider (21)
- # cljs-dev (8)
- # clojure (154)
- # clojure-dusseldorf (5)
- # clojure-filipino (3)
- # clojure-ireland (4)
- # clojure-italy (9)
- # clojure-russia (6)
- # clojure-spec (6)
- # clojure-uk (52)
- # clojureremote (3)
- # clojurescript (173)
- # clojurewest (14)
- # cursive (24)
- # data-science (2)
- # datomic (18)
- # defnpodcast (1)
- # devcards (1)
- # hoplon (4)
- # instaparse (29)
- # jobs (2)
- # juxt (1)
- # leiningen (3)
- # lumo (78)
- # off-topic (46)
- # om (9)
- # onyx (42)
- # pedestal (33)
- # perun (3)
- # re-frame (9)
- # reagent (6)
- # slack-help (5)
- # spacemacs (2)
- # specter (6)
- # unrepl (157)
- # untangled (99)
- # yada (32)
Hi, I'm having an issue with clojurescript after 1.9.473 not respecting my (:require [reagent.session :as session]). I can't find documentation as to why that would no longer work.
When I bump clojurescript to 1.9.495, session/put! no longer is found as a symbol, but reagent.session/put! works just fine.
(I'm using a cljc file -- ot works fine under clj, but under cljs, I'm getting midje.sweet errors)
@qqq Pretty sure midje is clj only
yeah clojure.test requires get morphed to cljs.test when in a cljs file
what's the logic with goog.closure not fixing the access to .-pageX,.-pageY attribute of mousemove evetns. Using native js interop js/document.addEventListener
works but not goog.closure.Events, only when it comes to these accessors. Only assumeing google developers are smarter people than me, than maybe .-pageX isn't recommented?
@hlolli that probably is for historic reasons and I think pageX
is not part of any spec, so browsers implemented it differently or not at all
yes I read something in that direction. The only accessor that doesn't get screwed up by page-scrolling is .-pageX. And as this works on firefox/chrome, then my compassion for those IE5- people is small.
yes, I kinda answered maybe my own question 🙂 I see they are very strict on compatability. On the other hand I feel safer using goog.closure with cljs. I guess this is just the way it should be.
also it is very easy to leak event listeners with the closure stuff since you need to dispose them
Anyone know if it's possible to build a JS library (CommonJS interface) using Clojure?
I'd imagine my lib would be shipped with the whole clojure runtime and google closure lib but since I'm targeting nodeJS it's probably fine~
I have something for that .. although its a bit alpha and I'm not really ready to release it yet
{:id :library
:target :node-library
:output-to "out/demo-library/lib.js"
:exports
{:hello demo.lib/hello}
the lib is here https://github.com/thheller/shadow-devtools
you add [thheller/shadow-devtools "0.1.20170403"]
to your :dependencies
in project.clj
can be in the :dev
profile if you have that (note it is not a plugin but dependency)
Is there an easy to way to generate some javascript from some clj forms? So without any goog.require/provide
and without any cljs.core
usage?
https://github.com/thheller/shadow-devtools/blob/master/shadow-cljs.edn as an exmaple config file
Just some functions for a documentation page, an I don't want to write js. Doesnt' need minification or anything. I know I couldn't use destructing an many other forms.
@akiroz be warned though it is alpha. I have been using it for years but some things are new and may have some rough edges
@rauh I have something you could use for that, but it would require some manual work
@thheller That's what I thought. 😞 For instance if I have simple functions like:
(defn set_width []
(let [el (.getElementById js/document "foo")]
(set! (.. el -style -width) "400px")))
That wouldn't depend on anything. All I'd need is the clj->js transpilation stage.I guess I can just use a normal cljs file and strip the goog.provide/require calls at the beginning of the file...
Just been through the examples in https://clojurescript.org/guides/javascript-modules. Very nice! For the example which uses nashorn to run babel and compile JSX in watch.clj, would there be a route to get a repl going yet?
has anyone here worked with Quiescent? Specifically, the quiescent tutorial app, the TodoMVP app? I'm newcommer to clojurescript and javascript, so I'm having trouble understanding this line in the project.clj:
(defproject mvp-maze "0.1.0-SNAPSHOT"
...
:ring {:handler todomvc-quiescent.serve/handler}
;; Note: it is not idiomatic to compile to, or serve from, the
;; project root but TodoMVC wants the index.html there, so we'll
;; adjust
:clean-targets [:target-path :compile-path "generated" "main.js"]
...)
@U3BALC2HH (friend studying this stuff with me) any guesses?
I think it's referring to the line above it, the ring handler registration.. There's another line in the serve namespace:
(ns todomvc-quiescent.serve
"Server for the todomvc app. Not necessary if demoing client-side
pieces only."
...)
I don't know what is normal, so I don't know what this project is doing to adapt to TodoMVC's requirements
what would be a good way to loop trough HTMLCollection (that gets returned by getElementByClassName) since its not seqable
[object HTMLCollection] is not ISeqable
solved it like this
(let [all-element-elements (-> (.getElementById js/document "x12-html")
(.getElementsByClassName "element"))
cnt-all-element-elements (.-length all-element-elements)]
(doall
(for [i (range cnt-all-element-elements)]
(aget all-element-elements i))))
@hlolli you could also look into extending the type https://github.com/levand/domina/blob/master/src/cljs/domina.cljs#L546
Too special-casey?
I wonder if this answer is a fulfilling one, http://stackoverflow.com/a/23624517/3714556
do not extend any protocol on the native stuff, they are mutable collections and wreck havoc if you expect them to behave like clojure maps
so far I've never bumped into mutable/immutable collision, but I'd be interested to see one, for science.
hey guys, i have never used javascript before, MutationObserver is the right things to fiddle with if i want to have all of the "events" from the DOM? is there a clojurescript api for this already?
@istvan no, this DOM API was deprecated
@istvan it depends on what type of events you are talking about
I cannot see where it was deprecated https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
document.addEventListener("click", function(e) { ... })
to track all clicks on the page
MutationObserver
is meant as a way to observe changes to the DOM itself, ie. new nodes being added
may i track all of the clicks at once or i need to add EventListener to each one of them?
if you attach to document
you get all events in the page, if you attach it to a specific elements you only get clicks in that element
so if you have 10 elements but all are contained in one other element you can do one event handler
in your example "click" is the type? -> https://developer.mozilla.org/en-US/docs/Web/Events/click
FWIW you can use ..
instead of ->
(.. event -target -value)
it’s a shortcut
I prefer ->
as ..
only does native interop (-> event .-target .-value (some-fn))
doesn't work with ..
@anmonteiro while you're here, is this safe: (js/console.log "test")
? It works fine, but I sometimes wonder if I should be using proper dot syntax. (I only do this in dev)
@danielcompton I use that all the time
@danielcompton I use that all the time as well
@danielcompton case in point: https://github.com/anmonteiro/lumo/blob/master/src/cljs/bundled/lumo/io.cljs
also just noticed something I should have deleted in that namespace 🙂
I think its fine for globals and would certainly be very upset should that ever be removed 😉
My searches are not really finding anything to obvious so: are there any popular cljs libs out there for url encoding/decoding? client-side (in cljs, not clj)
@mikerod: There's also https://github.com/lambdaisland/uri - I've not used it though but looks useful
is there a good resource for things that are commonly used from the Google Closure library? All I've really found are these API docs: https://google.github.io/closure-library/api/index.html
Also @mikerod, if all you need is to URL encode/decode and nothing fancier, there are methods built into the browser: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Is compiling UMD builds with webpack still the best way to get custom react components in a cljs app?
Hi guys, just starting out learning reagent in clojurescript. I'm slightly confused when it comes to rendering html attributes which aren't key value pairs, e.g. for something like <a class="uk-alert-close" uk-close></a>
how would I express this in the hiccip-esque syntax? [:a {:class "uk-alert-close" :uk-close}]
Obviously doesn't work since the hash-map is invalid.
I think any non-empty string would also work? Back when XHTML was trying to be a thing, people would write stuff like <input checked="checked" />
whereas today we would just write <input checked />
. (Note: This is beside the point. You should use true
.)
I think react doesn't allow arbitrary attributes
:data-uk-close true
will work though
I just posted https://groups.google.com/forum/?fromgroups#!topic/clojurescript/oiXKTnJ2r9o and https://github.com/thheller/shadow-devtools ... it might interest some people here. happy to answer questions.
Is it possible to convert some string s
such as: "#object[user$core$f \"function user$core$f(a,b){\nreturn (a + b);\n}\"]"
into some object o
where I can (.call o 1 2)
to get 3? Outside of self-hosted mode?
I forget the details, but I recall it gets much more complicated if there are multiple arities for the function
it's not a simple built in feature
@john well you can (js/eval "function user$core$f(a,b){\nreturn (a + b);\n}")
which will give you function in that case
Hi everyone! I'm a recent Clojure(script) convert, and I'm trying to make a simple CLJS/Reagent project. Problem is, I want to have a different ns for each page. https://clojurescript.org/reference/compiler-options#modules modules seem to be the natural solution, but they require some optimizations to work correctly. On the other hand, figwheel requires no optimizations to be enabled. This leaves me at a loss for what to do. Keep in mind that I have very little experience with clojure or any build tools. (BTW, is this the kind of stuff clojurians is for?)
you don't need modules in order to have an ns per page
but what do you want these namespaces to do? is it that you want a different minimized js file for each page?
(because this is not what namespaces in clojure are for)
<script src="/js/compiled/global-init.js" type="text/javascript"></script>
<script src="/js/compiled/out/page_name/page.js" type="text/javascript"></script>
<script type="text/javascript">goog.require("page-ns");</script>
I was thinking that it could compile all the relevant js files into just one big file, and just load that for each page. Is that how it works?
this is how most of us do things, yes
as I understand it, thanks to browser caching, it makes sense to put all your js in one file for the app, instead of having a different mix of smaller files per page
but I'm not an expert, someone might have another suggestion
I suppose that would be an advantage, but I was/am getting tired of all the goog.require
js that I was writing at the end of each file. Using :main
in the project.clj (from how I understand it) takes care of all the boilerplate for you.
my approach would be to have a main that requires all your pages, and uses the location to decide which one to launch when it loads
or query, or fragment, or however you organize it
from the main ns
that would be one way - but there's stuff your code could check without needing that to be called explicitly
(eg. .-location of the browser etc.)
since I think it's easier to not have varying inline js in various html files
@jatkins: As a point of context, I've written plenty of CLJS and never had to write a single goog.require - so I think there's an easier way for you to get started. Check out the reagent and related clojurescript episodes at https://lambdaisland.com/episodes - they're very good and easy to follow, and there's a free trial so you can see if it's something that interests you further. There are also a lot of very helpful people in the #beginners channel that should be able to point you in other good directions as you run into more stumbling blocks.