Fork me on GitHub
#clojurescript
<
2016-02-16
>
akjetma02:02:35

is it possible to compile a self-contained js snippet from a clojurescript snippet in the browser? i would like to make a collaborative coding environment with an iframe’d output window like codepen or jsbin. i feel like the best way would be to have a fully self-sufficient string of js that i just inject into an iframe. there are other ways around this if it’s not possible, though.

akjetma02:02:53

just thought i’d check before i went too deep down the compiler rabbit hole

akjetma02:02:11

right now i have something that will translate (println "hey”) to cljs.core.println.call(null,"hey”); but obviously cljs.core.println is not defined within this output.

akjetma02:02:51

oh wow, i see there is a lot of discussion in this channel of similar things not too long ago. apologies if this question is redundant

echristopherson02:02:37

I never used the search function before

soxley02:02:16

So I'm taking a look at silk right now for routing, and I think it looks like a better, more flexible solution than secretary. Has anyone else found that to be the case? or would you recommend something else? https://github.com/DomKM/silk https://github.com/gf3/secretary

soxley03:02:28

Actually, bidi looks good, too: https://github.com/juxt/bidi

soxley03:02:40

I think I'm going to go with bidi. Looks relatively simple and it will fit all of my needs

roberto03:02:47

what makes it more flexible?

akjetma03:02:52

ooh i like that it is not macro-based

mfikes04:02:05

@akjetma: Type (println "hey”) into the Compilation box at http://swannodette.github.io/2015/07/29/clojurescript-17/ and you’ll see that cljs.core.println.call(null,"hey”); is dropped into the box on the right.

mfikes04:02:38

@akjetma: If you want to be able to evaluate it, just look at how some of the online REPLs like http://clojurescript.io are built.

akjetma04:02:49

Oh, wonderful! thank you I will take a look at this. I am looking for output that includes the definition of, e.g. cljs.core.println but this might be the wrong way to go about it

mfikes04:02:52

I suppose http://clojurescript.io is a bad example—it doesn’t appear to have print output hooked up. But http://clojurescript.net does. simple_smile

mfikes04:02:29

@akjetma: If you evaluate js/cljs.core.println in those two online REPLs you will see the JavaScript. http://clojurescript.io employs :simple and http://clojurescript.net employs :none

jimmy04:02:11

hey guys how to do smooth scrolling in clojurescript ?

akjetma04:02:05

ahh, yeah, so the problem i’m running into is: if i want to have a sandboxed environment (iframe with a separate window from the context in which the clojurescript is compiled) to evaluate the compiled clojurescript, i need to have all of the core functionality of clojurescript available to both sections. i am thinking i will split the code-writing/compiling section and iframe/sandbox section into closure modules and they can both have the common/core parts of clojurescript in a tertiary script.

akjetma04:02:21

thank you for pointing out that dnolen post and the js/cljs.core.println bit though, that is very helpful

mfikes04:02:23

@akjetma: Yeah, what you are describing sounds doable. Just up to your imagination and how you want to implement something like that.

mfikes04:02:29

@akjetma: I’ve also pondered if it is possible to produce a compiler that is built with :advanced (to keep it small), but then evaluate the generated JavaScript in an environment that has the standard library JavaScript generated using :none. (Not really what you are doing, but I was wondering about that nonetheless.)

akjetma04:02:13

Ah yeah, that would be perfect/the ideal clean solution

noonian05:02:07

Is it possible to get any information about what is defined in various namespaces in a repl context in cljs? Like ns-interns in jvm Clojure ideally but interested in any ways this may be possible.

mfikes06:02:58

@noonian: ns-interns works, dir works, etc.

mihaelkonjevic07:02:24

What is the best way to package a javascript library inside the clojurescript one? I'd like to avoid the situation where people have to install the js lib separately to be able to use my cljs lib

martinklepsch10:02:38

@nxqd: Look into goog.dom.fx.Scroll, worked great for me the other day

mihaelkonjevic10:02:45

@nullptr: Thanks, will check out their docs

kmandrup11:02:39

Has anyone used JSPM with ClojureScript. Looks to me like a nice, easy way to use :foreign-libs, using SystemJS to do the heavy lifting, then just ES6 imports from there...

kmandrup11:02:11

I see, the obvious way moving forward is to use cljsjs I guess? 😉

soxley15:02:10

@roberto: with secretary, I couldn't find a way to pass in anything custom to my route handler. For example, I might want to pass in some service to all of my route handlers. With silk or bidi, this is easy, since they just translate the (partial) URL to a handler or whatever data you want and then it is up to you to actually call the handler.

mihaelkonjevic15:02:10

@roberto Keechma has a pure data processing based router http://keechma.com/api/keechma.router.html so that might work for you too

soxley15:02:23

@mihaelkonjevic: I was actually the one looking for the router. Thanks for the suggestion simple_smile

kmandrup18:02:28

hey guys, does cljs have any support for ES6 syntax beyond module import?

maria18:02:54

@kmandrup: there are the :language-in and :language-out compiler options (https://github.com/clojure/clojurescript/wiki/Compiler-Options#language-in-and-language-out). The description in the wiki is outdated, meaning you can also set :language-in to :ecmascript6. Will update them in a bit.

kmandrup18:02:06

Nice to see you here @maria simple_smile I'm just curious how to interop with popular modern JS frameworks, where many now leverage new ES6 syntax...

kmandrup18:02:54

Yeah, we need some better docs on modern JS interop

kmandrup18:02:49

@maria any examples on using :ecmascript6 ??

maria18:02:03

@kmandrup: so the foreign-libs you want to include use ES6 features?

kmandrup18:02:00

I'd like to write an ES6 compatible class from within cljs, is that possible?

maria18:02:37

@kmandrup: no, I don’t think so, since all the code that the ClojureScript compiler generates is ES3 compatible

dnolen18:02:32

@kmandrup: not sure what advantage that would offer you … ES6 classes are mostly about syntactical sugar over existing functionality

dnolen18:02:47

there's very little reason to support any ES6 syntactical feature in ClojureScript at this time

kmandrup18:02:57

I understand that, just simplifies not having to "reverse engineer"... say I'd like to integrate with Angular, Aurelia, Ember or whatever... all requiring ES6.

dnolen18:02:42

@kmandrup: “requiring”

dnolen18:02:04

assuming everybody has to compile to ES5 anyway - I don’t know what that really means

kmandrup18:02:41

Just curious if I have to work with prototype directly... what about getters/setters and all the other "magic spells" of ES6, would that still be simple in CS?

dnolen19:02:35

no but there’s no real need

dnolen19:02:22

another advantage of Closure Compiler is you can write whatever bits of JS you actually need and compile it all together

kmandrup19:02:43

Sure, I watched @maria presentation on compiler internals... but not sure where I would "write whatever bits of JS you actually need"? except by direct compiler extension/integration?

dnolen19:02:47

just write a JavaScript file

kmandrup19:02:56

Sure, but that's what I was hoping to avoid. The whole point... escaping mutability hell while writing and leveraging ES6 code and not having to use Immutable.js etc.

dnolen19:02:44

the later part of your statement seem contradictory

dnolen19:02:14

why does ClojureScript need sugar for making mutable classes when you can just write them directly?

kmandrup19:02:35

Just trying to avoid having to reverse engineer latest libraries/frameworks to ES5, such as: http://stackoverflow.com/questions/32028553/aurelia-computed-properties-with-es5

kmandrup19:02:37

I get the general gist, I'd have to find ES5 or ES3 equivalent syntax to achieve the same functionality and then wrap it with CS macros? Thanks simple_smile

dnolen19:02:03

ClojureScript avoided all class sugar in the past because there wasn’t a standard way to create “classes” in JavaScript just various competing patterns

dnolen19:02:05

ES2015 class sugar will eventually dominate but I don’t think we’re really there yet especially since most MVC frameworks are just fundamentally incompatible with ClojureScript wrt. mutability

dnolen19:02:35

a vast majority of ClojureScript people use React which doesn’t have these problems and doesn’t really require ES6 classes in any deep way

dnolen19:02:26

eventually the demand for other ES6 stuff may be great enough to desire some kind of defclass patch, but I would say we are not there yet

kmandrup19:02:51

I see your valid points simple_smile Thanks for your time, I know you must be busy! I'm trying to write a book on native app dev with ClojureScript while learning it... since most of the resources in the wild seem to be out dated and don't delve into using React Native, Ambly, Electron etc.

kmandrup19:02:45

Yeah, exactly my point. Since React still support the old ES5 syntax simple_smile I'm also exploring reagent and om.next for the same reason! Cheers simple_smile I owe you a beer!!

kmandrup19:02:35

I also much prefer the pure functional/reactive approach of React, my questions were more "on principle"

dnolen19:02:23

right I just want to see wider acceptance and more “pressure” before pursuing it

dnolen19:02:58

but my suspicion is the tail of the jQuery JS world is very, very long

kmandrup19:02:55

No worries, was just curious what was currently possible. Would be nice to meet up in a pub in Brooklyn sometime... Cheers!

dnolen19:02:26

@kmandrup: or swing by LispNYC or ClojureNYC in the city, I often attend simple_smile

kmandrup19:02:32

@dnolen: Awesome! See you around simple_smile

kmandrup21:02:08

For experimental support (fork?) of select ES6 constructs, couldn't we make the compiler's Emission step optionally be configured to perform an additional transformation step (such as running through a transpiler), then have class, extends etc. "fall through" and be transpiled to ES5?

dnolen21:02:12

@kmandrup: it’s not that simple - this discussion probably belongs in #C07UQ678E