This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-21
Channels
- # bangalore-clj (1)
- # beginners (60)
- # boot (30)
- # cider (7)
- # cljs-dev (10)
- # cljsrn (2)
- # clojure (163)
- # clojure-conj (10)
- # clojure-france (1)
- # clojure-greece (2)
- # clojure-italy (7)
- # clojure-russia (41)
- # clojure-serbia (22)
- # clojure-spec (41)
- # clojure-uk (41)
- # clojurescript (178)
- # cursive (36)
- # datascript (1)
- # datomic (23)
- # dirac (38)
- # graphql (12)
- # hoplon (20)
- # immutant (32)
- # instaparse (3)
- # keechma (1)
- # lein-figwheel (18)
- # leiningen (8)
- # liberator (1)
- # luminus (30)
- # lumo (29)
- # off-topic (18)
- # om (17)
- # pedestal (7)
- # planck (37)
- # precept (1)
- # re-frame (67)
- # ring-swagger (2)
- # timbre (1)
- # untangled (8)
- # vim (2)
when I include a foreign library, how do I figure out the name of the object to call things from?
for example, I include an NPM package that has module.exports = React.createClass({ stuff here... })
@deadghost Have you tried (def foo (js/require "foo")) and then (.whatever foo arg1 arg2)?
Hi all! I'm experimenting with re-frame and I'm looking for a simple example of password-based authentication. I'm familiar with buddy for ring-based apps, but I'm not sure how to handle this in SPA. Thanks in advance!
@deadghost you’d need to look at the foreign lib, the name it provides should be available there somewhere
@thheller I should typically look for the export in the src and not the dist right?
@deadghost Kinda depends. Regular require works for clojurescript modules which You've imported, e.g.
(ns my-namespace-here
(:require [foo.bar.baz]
[foo.bar.foobar :as f]
[my.random.mathlib :refer [myadd mysub]))
(foo.bar.baz/<smth> ...)
(f/<smth> ... )
(myadd ...)
For NodeJS it's a little different:
You need to require the cljs.nodejs NS and use the 'require' function defined therein.
See https://mmcgrana.github.io/2011/09/clojurescript-nodejs.html for an example (under the section "Node.js Libraries")@pseud different issue, foreign libs are only imported via require but their name is not defined by it
Sure, but as the example shows, you just assign the output of require to some var using def and you're done. ? Unless I'm missing something..
@thheller trying to get https://github.com/benrlodge/react-simplemde-editor working
@deadghost http://github.com/cljsjs project concerns itself with the wrapping of native JS modules for use in front-end CLJS applications. While their build scripts might be a tad advanced for your needs (?) it might be worth looking into, especially if they happen to wrap other react components you might recognize. My understanding is that you need to ensure the code is included in the JS bundle you end up emitting and that it will take an externs file because otherwise the google closure compiler on which CLJS relies for tree shaking will not pick up on your use of the functions defined in the JS lib and simply discard them. I think there were some developments wrt. the need to define extern files, but I haven't looked into it.
@deadghost that looks like the dist file includes its own React. that will not be easy to embed on its own
Using cljsbuild with a :source-paths
set, where should (require)
look from the REPL?
seems to only find clojurescript namespaces if I put them in my top level :source-paths
, which I didn't think was the pattern in lein
AFAIK top-level :source-paths
are for clj code (macros in cljs) and cljsbuild-level :source-paths
are for cljs files only. Paths are implicitly inherited from top-level to cljsbuild-level.
@darwin you're confirming my understanding. Which puts me back into confusion with: why on earth is the repl failing to require the cljs namespaces?!
it knows only top-level stuff, cljsbuild is just a weird uknown plugin for it, I believe
yeah, afaik it parses the project.clj for the cljsbuild config (even uses spec to validate it now too)
https://github.com/bhauman/lein-figwheel/blob/250dcb6911d402609fe283afb3b98e081d068c3c/examples/implicit-js-reloading/project.clj#L18 that's odd. not "src-cljs" just "src"
what is odd? “src-cljs” is the default :source-paths
if you don’t specify it (cljsbuild default)
@darwin did not know that! I thought it was odd that it was being set to "src" for cljsbuild also though?
I don’t follow. Anyways, do you have multiple build-ids in your project.clj? Maybe your figwheel is not picking up the expected one.
@darwin I have 4. I have done a figwheel-switch & start though. It seems to connect to the browser okay. Reloading works too.
the build all works. I notice that figwheel 0.5.9 fixed require somehow, so I guess that means something changed in that regard.
you could write a macro and grab effective java classpath in it, maybe that could hint what went wrong
not sure about the figwheel issue you are seeing but you can add your :source-paths
for lein
as well
@thheller it's crossed my mind already to try shadow cljs tbh 😛. We'll see how long my resilience holds up for fixing this.
i.e. I want to fire up a browser (which ran run js), then I want to control this browser via clojure/cljs
I want to do things in cljs to sa y"fire up browser, go to http://flights.google.com, search for BLAH to BLAH, get the HTML, parse the table"
@qqq oh, browser automation. By "control browsers" I thought you just meant code execution.
@qqq maybe it's more efficient to create a JavaFX web view and control that one directly via Clojure instead of ClojureScript.
@qqq I only ever played around with it and got stuff out by injecting JS, but I'm pretty sure you can (javafx.scene.web.WebEngine#getDocument)
@qqq those tools are usually driven by JS code .. you can write that JS code in CLJS
ie you translate this: https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs into CLJS
how do I extend-type Object in Clojurescript ?
(extend-type object
YourProtocol
...)
doesn't work
how do you test this?
well, what I mean is, extend-type object should be the default implementation, but when I throw a boolean at it I get: No protocol method Rendering.render defined for type boolean: false
a snippet of code would be useful
ok, in Clojure you can do this:
(defprotocol Q (q [this]))
=> Q
(extend-type Object Q (q [this] 8))
=> nil
(q 7)
=> 8
but in Clojurescript:
dev:cljs.user=> (defprotocol Q (q [this]))
nil
dev:cljs.user=> (extend-type object Q (q [this] 8))
#object[Function "function (this$){
return (8);
}"]
dev:cljs.user=> (q 6)
#object[Error Error: No protocol method Q.q defined for type number: 6]
Ahhhhh
stupidly I was reading the documentation for protocols
but does the rule of using lowercase names of types, like boolean not Boolean, follow in CLJS ?
- for extending other types
@octo221 Those lowercase names are hard-coded symbols with special meaning: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/core.cljc#L1239-L1247
hmm ok so
Keyword
for keywords, but number
for Numbers@octo221 You can use js/Number
, but it is discouraged. (It will also cause a compiler working to be emitted.)
ok but no cross-platform way of denoting a type ?
(in general)
That’s an interesting question. I’m not aware of built-in ways to abstract over hosty aspects. Generally that stuff is put into reader conditionals these days, I suppose.
of course, fine. Hey thanks for your help @mfikes !
Try looking at this fork of om.next https://github.com/anmonteiro/om/tree/js-modules
@octo221: there no cross-platform way to talk about native JS types because the types themselves are too host-y
hi! I need to
import CardStackStyleInterpolator from 'react-navigation/src/views/CardStackStyleInterpolator'
as described in this issue https://github.com/react-community/react-navigation/issues/1400. How I can do? Thanks 🙂@dnolen understood, except, if a thing returns true for number? then it's of type Number (in some sense) - or am I thinking about types all wrong ?
@dnolan hmm, thinking about it, another way to test for a type, other than by its name, is to ask what functions can it can be applied to. Like respondsTo: in Smalltalk
there’s the fundamental problem that json has neither keywords nor namespaces…
so you need to set up a conversion convention I guess
can anyone tell me when to expect perf. improvements @mfikes was talking about recently (to be released)
@ag There are a boatload of changes in master right now, so it is worth giving them a spin.
well, if a programmer says Friday it can mean Friday in June, December or in month of Phobos based on a Martian calendar 😉
Yeah, it is good stuff. 🙂 If you look in JIRA, there is a roadmap, with 20 unresolved issues targeting the Next release. If all of those are to be done, then Friday would be a challenge, IMHO. Dunno if that’s really the plan.
So, every time I try to get started with cljs, I get terrified by framework and tooling choice.
it feels like picking the wrong framework will lead me to wasting weeks and weeks of effort as I slowly realize that the framework is either too opinionated so it prevents me from doing what I want, or it's not robust enough so it prevents me from doing what I want
do I want to learn ohm.next and have plenty of rope to hang myself, or use brutha and have to make all my rope from tree bark?
@tjtolton: from my personal experience: switched to Boot - regretted for not switching sooner. used Reframe, then tried Om.Next - to be honest this one was really hard, regretted for not using Untangled.
if you pick up Om and have to use it in a project with more than 3 people, I strongly suggest someone to become "expert" and then patiently explain it to others. Otherwise it would be really hard
there's something about Om.Next's novelty approach. Everyone who starts learning it, soon starts questioning its design. Most of the time without fully understanding it
where boot is practical, flexible and composable, but its also unstable, imperative, and side-effect first design. Lein is declarative, pushes side-effects to the edge, battle tested, stable etc, but apparently it quickly becomes a nuisance since cljs is mostly file transformation
tjtolton: lein is fine, but boot is woot. why do you think boot is unstable? re: side-effects, boot is very functional, filesets are immutable.
tjtolton: yeah there have been major improvements, i think its pretty stable now, and pretty widely-used.
@U0LGCREMU also, I just want to say that I am completely sold on boot exclusively because of that sweet rhyme
there's got to be a stickied topic for this somewhere. people probably ask every ten minutes.
if you want to learn clojurescript any of these things are going to help you there, but you're also going to be learning something else along with
mattly: yeah, I guess my question is which choice will lead to the most transferrable something else
om.next is well-suited towards a particular problem, but if your goal is just to build a simple side-project it's way overkill
2 goals. 1 is a specific app I want to make, and then grow and support it if it becomes something people are interested in. 2 is learn how to make that process repeatable
what I've done for front-end tools is try them out on something simple to see how I like them
@U053V4R5N makes sense I suppose. I have something simple in mind, but I am going to have a limited time to implementation, and I basically get one doover
hi, are there potential issues with core.async pub/sub in cljs? I have a publication for which I have 2 subscribers which listen for different events on the same topic
It looks like I'm only getting notifications to one subscriber at a time, like I get a bunch of messages for sub1 and nothing happens on sub2 and then later the roles are reversed, all the while I see messages for both event1 and event2 being pushed on to the channel that the pub is associated with
javascript doesn't have threading like the JVM so I'm wondering if maybe I'm expecting too much here?
sure, making something small that accuratly reflects what I'm doing is a bit of a chore but I'll try. I was mostly just checking to make sure that it makes sense to be able to expect channels to handle many things happening at the same time in clojurescript
I have something like this (def bus (chan)) (def t-pub (pub bus :topic1)) (def sub1-ch (chan)) (def sub2-ch (chan)) (defn looper [ch handler-fn] (go-loop [] (handler-fn (<! ch)) (recur))) (sub t-pub :evt1 sub1-ch) (looper sub1-ch sub1-handler) (sub t-pub :evt2 sub2-ch) (looper sub2-ch sub2-handler)
and then lots of things push on to the bus (go (>! bus {:topic1 :evt1 :payload "foo")) (go (>! bus {:topic1 :evt2 :payload "bar")) etc
pushing stuff on to the bus is interleaved between evt1 and 2 pretty heavily, however the actual calling of the the functions sub1-handler and sub2-handler aren't really interleaved or maybe there is slight overlap for just a moment
sanity check needed. i have clojure data to send to my cljs frontend, which stores it in datascript. i understand transit would be more efficient than edn at least in some cases, is that right? but then my frontend needs to pass some of that data to java objs (webcomponents). clj->js works, but i'm wondering how others handle this situation. is there is a best practice for this sort of thing? e.g. i could drop datascript and move query/filter logic to the backend and just send javascript.