Fork me on GitHub
#clojurescript
<
2015-10-20
>
gabe00:10:34

what’re people using for client-side routing?

potetm00:10:17

@gabe: https://github.com/gf3/secretary is pretty popular last I checked.

gabe00:10:02

@potetm: that’s what I figured. I saw bidi as well and wanted to hear people’s take either/both

richiardiandrea01:10:26

hello guys, what do I have to require in order to rebind err ?

richiardiandrea01:10:34

can't understand why cljs.core/err does not work

richiardiandrea01:10:59

ah of course, there is no err in cljs.core...

bhagany02:10:25

I'm looking for a way to go from markdown to hiccup-like data, using clojurescript on node. Has anybody done anything like this?

bhagany02:10:44

I've tried to go from markdown to html using https://github.com/yogthos/markdown-clj, and then from html to hiccup with https://github.com/davidsantiago/hickory, but the latter appears to depend on js interop that is only available in a browser environment

richiardiandrea03:10:36

mmm...never tried...if you do it though, let me know because it could be useful for testing my https://github.com/arichiardi/reactive-markdown

richiardiandrea03:10:58

actually i could use markdown-clj

richiardiandrea03:10:18

actually my library makes little sense now that I have see what

markdown-clj
does 😓

jaen07:10:22

@gabe: I, for one, us bidi; I like being able to share the routes between frontend and backend and the fact that routes are not magical macros but just plain datastructures.

greywolve09:10:41

+1 bidi is great

greywolve09:10:06

using it in production on one of our projects, and so far so good

danielbraun09:10:29

+1 bidi. routes as data is very useful

jaen09:10:53

Except the part where the route definitions are a bit finicky and slightly unreadable (I'm never 100% I put the right amount of brackets), but that's a small price to pay to be able to share routes and get reverse routing, since you can just split the routes into several def/defns.

greywolve09:10:07

haha yeah that is a bit annoying

jrychter10:10:40

…and some of us think that "routes" are the wrong approach altogether simple_smile (Rails heritage) and use URLs split into tokens to provide composable mapping of URLs to components.

jaen10:10:57

@jrychter: how would that work exactly? And if I'm getting that right wouldn't giving a component it's own subroutes that are then composed into one big route map of all components when the system boots be isomorphic to that? Something like modular does.

jrychter10:10:18

@jaen I have to write it up, because I end up explaining it (badly) often… Basically, you split the URL into tokens and pass them down the component tree. A component has the option of consuming some tokens. Which means there is no single "routing table", which means you are free to move components around without maintaining routing information in two places. I don't know the modular approach — but I guess you might build a declarative system where a global map is built from all components. Sounds complicated, though.

jrychter10:10:51

@jaen There are drawbacks, so it's not all roses — but I'm pretty happy with this approach so far. The major drawback is that you need to explicitly pass additional params down the component tree.

jaen10:10:45

It basically just has a protocol called RouteProvider that returns a route subtree which then it collects from the constituent components and builds the route map. But yeah, I think it might be more complicated to implement than what you're describing, since in your case there's no need to gather all the route subtrees, since you walk the component tree on each request.

jaen10:10:51

I guess that's an interesting approach

jrychter10:10:57

@jaen You also don't get "full" reverse routing — building URLs within a component works fine, but for global links I just write functions that explicitly build them. So far this has been OK for me, because there are typically quite few "global" links. Most navigation happens with a component (menu, tabs, whatever). And you don't get "shared" client/server routing, which isn't a problem if you build isomorphic apps.

jrychter11:10:09

I really have to write this up.

jaen11:10:26

Yeah, that would probably be an interesting read.

jaen11:10:15

As for not having isomorphic routing - well, if you venture into components I guess that's one thing you have to sacrifice

jaen11:10:37

I don't imagine it would be easy to get full routes from a system if it's instantiated only at runtime

itrillian11:10:38

Hi all, is the es6/amd/commonjs module support for cljs actually done or is it still a wip, I can't see a reference to it here: https://github.com/clojure/clojurescript/wiki/Dependencies but it is referenced under compiler options here: https://github.com/clojure/clojurescript/wiki/Compiler-Options#foreign-libs

jaen11:10:58

@itrillian: you can use it for single files with :foreign-libs I think?

maria11:10:16

@itrillian: It depends on what you want to do. There is already very basic support for JS modules.

maria11:10:21

@jaen: Well, you can actually already include multiple files as longs as they are using relative paths for their requires 😉

itrillian11:10:55

@maria I'm trying to make a case for clojurescript to use in an upcoming project at work, but there are some concerns, one of them is how much trouble it is to handle foreign libs, so I'm wondering if the cross modules feature is actually ready to use in a production environment since we already have some other homemade libraries that use commonjs modules for example

itrillian11:10:24

@jaen yes but I found it strange that it was not referenced on the dependencies page

jaen11:10:37

@maria: ok, fair point, though this still limits it to small and simple pieces of code (preferably you have ownership over), no one in their right minds would want to specify all 170 files of React by hand (at least I know I wouldn't which is why I started working on it)

jaen11:10:09

@itrillian: I wouldn't know why exactly, but I guess that's since it's still work in progress

thheller11:10:32

@jaen is it possible to turn on {:pretty-print true} for the conversion process?

maria11:10:18

@itrillian: You can have a look at a small example project here where I am including React as a CommonJS module https://github.com/mneise/circle-color

jaen11:10:44

You can process single files with relative requires by specifying them all in :foreign-libs, but anything bigger is not really supported outside of my fork (and it doesn't yet support everything either)

jaen11:10:51

@thheller: hm, didn't try

maria11:10:23

@itrillian: Or here is another example where I am including CodeMirror and hammer.js as CommonJS libs https://github.com/mneise/cljs-present/blob/master/scripts/build.clj 😉

jaen11:10:02

Oooh, a presentation thing

maria11:10:14

Yeah, still working on it though, but already used it for a small presentation (http://mneise.github.io/talks/2015-09-15-akjs/index.html) 😉

jaen11:10:32

I like impress.js very much, would be nice to have something similar in Cljs

maria11:10:31

@itrillian: It really depends on what you are trying to do. Someone at a meet up told me a couple of weeks ago that they are already using JS module support in production for their own existing CommonJS libraries. But if you are expecting it to work out of the box with most libraries on npm, this will not be the case.

jaen12:10:47

@itrillian: basically your best bet right now is to use browserify/webpack/whatever-is-the-node-flavour-of-the-month to preprocess your files by removing modules and put that in :foreign-libs as plain JS libs. Otherwise if your lib is simple enough you might follow what Maria did in her samples and use her :foreign-libs module options.

itrillian12:10:17

@maria: ok thanks for the info 😃 will have to investigate how much impact that will have with our own libs

itrillian12:10:44

@jaen nice suggestion, thank you

thheller12:10:12

@maria: trick question: how do you access React.DOM.h1() in your circle example? simple_smile

mfikes12:10:32

FWIW: The React community finally had to move away from Slack (hit the user count limit) and now they are using Discord, which is built on React and React Native.

martinklepsch12:10:42

There’s a #C0CB40N8K channel if people are interested discussing this kind of stuff.

gabe13:10:18

@jaen et al: thanks for your input

gabe13:10:51

I ended up starting w/ bidi last night. I’m using it for the front-end and like that I can see my app layout as a route tree. All those nested maps and vectors take a bit of getting used to, but I think overall it’s a good approach

borkdude13:10:05

Some communities are using gitter

jaen13:10:00

But isn't gitter centred on one project and doesn't have subchannels? At least, I didn't notice it having them.

martinklepsch14:10:38

There’s a way to get subchannels in Gitter.

ul15:10:55

why Atom doesn't implement ISwap and IReset, but there is special case in swap! and reset! functions? For performance reasons?

ul16:10:08

and another question: do watches prevent atom GCing?

jeremyraines17:10:59

how do you refer to module.exports in a clojurescript file?

jaen17:10:12

@jeremyraines: what do you want to do exactly? But if you want to access module.exports then probably that's not something Clojurescript (yet) support.

jeremyraines17:10:36

the last line, which sets it up to run on Lambda, is app.handle(module.exports . . . I just found something I’m going to try which is (.handle app (.-exports js/module))

roberto17:10:11

node/module

roberto17:10:09

(-> node/module .-exports (.handle app))

jeremyraines17:10:22

might be right, but either I don’t understand lein-cljsbuild yet (likely) or the fact that this example doesn’t actually set anything to module.exports causes the generated js to be northing but the goog.require bits

roberto17:10:07

yeah, I haven’t tried using cljs with nodejs. Feels too hacky at this moment. Maybe in the future.

bhagany18:10:07

@jeremyraines: you're looking for the cljs.nodejs namespace

jeremyraines18:10:04

I have it in the project

bhagany18:10:08

I usually do something like:

(let [node-package (cljs.nodejs/require "the-package-name")]
  (do-stuff))

jeremyraines18:10:46

OK, thanks. I think I’m able to use packages

jeremyraines18:10:54

just not export a usable one yet

bhagany18:10:13

ah, you want to export something from cljs to be usable in vanilla node?

jeremyraines18:10:44

yeah. Here’s a js file that does what I want:

jeremyraines18:10:14

e.g. just export one function

jeremyraines18:10:46

I feel like I can get there, but this example (which is a nice library wrapping the functionality I need to put in that function):

jeremyraines18:10:18

only wraps module.exports

jeremyraines18:10:47

either way, I’m studying how this project does it . . . and it’s considerably harder than I would’ve imagined

jeremyraines18:10:59

where they do some templating to generate (before? after? during?) the actual cljsbuild

bhagany18:10:08

okay, got it. I don't have any experience using cljs code from javascript land, but I am familiar with cljs-lambda

bhagany18:10:27

they use the template as a quick and easy way to do what you're looking for simple_smile

bhagany18:10:43

it's not a very flexible approach, but if you're only targeting lambda, it works

bhagany18:10:59

I think the template part happens after the build step, fwiw

jeremyraines18:10:17

yeah, I see that now. Starting to get it but I wouldn’t call it easy

bhagany18:10:27

heh, well, easier than hacking the compiler. I suppose it's relative

jeremyraines18:10:22

thanks for clarifying that that was the mechanism

jeremyraines19:10:52

anyone know why I might be getting this error when compiling to js:

jeremyraines19:10:57

java.lang.RuntimeException: No reader function for tag js

jeremyraines19:10:35

is there something I need to require in the ns for #js {:some “object”} to work?

jr19:10:43

is that a cljs or cljc file?

jeremyraines19:10:39

ugh . . . .clj I forgot to rename it; time for a break. thanks

borkdude20:10:46

(also posted in #C03S1KBA2)

angusiguess20:10:06

@borkdude Have you checked out prismatic's schema?

borkdude20:10:43

@angusiguess: yes, I use it. What about it?

angusiguess20:10:18

Well I suppose one way we could think of schema is for domain modelling, in that we use it to define constraints around our data and how it flows through the system. I'm not super experienced in domain modelling but isn't schemafying collections sort of like defining value objects, and don't functions act as relations on value objects?

borkdude20:10:55

sort of yeah. Schema is more a validation library. You don't construct data with it.

blissdev20:10:30

is the correct way to stop eventPropagation on a react event? :onClick (fn [e] (.-stopPropagation e))

jaen20:10:57

Yes. Or at least - that's what I do.

blissdev20:10:10

hmm… doesn’t seem to be working, wonder what I’m doing wrong

blissdev20:10:45

click is still being triggered on the parent

jaen20:10:09

Hm, interesting

jaen20:10:28

There's also stopImmediatePropagation on events, I assume React implements that as well

blissdev20:10:50

I tried that, no effect, and also it seems they only implement normal?

blissdev20:10:12

perhaps I could pull out the raw event and do it

jdw20:10:19

@blissdev Might be wrong, but looks to me like you’ve got a hyphen in there which will cause problems

jaen20:10:30

oh, right

blissdev20:10:37

ohh… am I doing prop access?

jaen20:10:41

You then get a function returned not called

jdw20:10:54

Yup - drop the hyphen and you will invoke

jaen20:10:25

The kind of silly errors that would be avoidable with a type system, alas we all code in a dynamic language ; d

blissdev20:10:49

hmm perhaps simple_smile

cigitia20:10:35

In what version was JSDoc compile-time checking (https://github.com/clojure/clojurescript/wiki/Compile-Time-Type-Checking) added to ClojureScript? I’m having determining that from the changelog, and trying out examples doesn’t seem to be working for me.

jaen21:10:27

after .48 that's for sure

dnolen21:10:19

@cigitia: it needs more work and I don’t have the bandwidth for it at the moment

dnolen21:10:42

yet another place for someone to do some impactful yet pretty straightforward compiler work

cigitia21:10:07

@bensu @dnolen Thanks for the answers!

chris-andrews21:10:43

Is anyone familiar with how core.async is managed as a dependency within clojurescript? I am trying to use the “poll!” function, but I get the message: "Referred var cljs.core.async/poll! does not exist”. Is cljs.core.async distinct from org.clojure/core.async?

jr21:10:41

@chris-andrews: there hasn’t been a core.async release in over a year. unfortunately the current release does not have that function

chris-andrews21:10:14

@jr: Thanks, and bummer. Do you know if the clojurescript core.async is accessed via the clojure core.async package? If so, I could install a snapshot locally and use it. But since you require it via cljs.core.async I’m not really sure what that resolves to

jr21:10:33

the core.async repo provides both namespaces but I’m not sure how to compile and package it

jr21:10:07

I think there are issues with some new features of unreleased core.async so I wouldn’t recommend using it until the core team works it out

chris-andrews21:10:35

ok, thanks for the input. I’m really just trying to find an easy way to flush a channel for ui events, maybe it’ll be easier for me to just find a better way to do that

jr21:10:21

(async/into [] ch) should exhaust the channel

chris-andrews21:10:16

@jr: Won’t into also close the channel? I need to keep using the channels, but get rid of any old mouse move/click events

chris-andrews21:10:12

Maybe the best workaround is to just close the channels and create new ones?

jr21:10:41

when would you want to flush the channel?

jr21:10:47

why not use a buffer?

chris-andrews22:10:29

There are a few places where it’s used, but the gist of it is things like: I’m using sliding buffers of length 1 for mouse down, up, and move. I have some logic where if the first take after mouse down is a mouse up, it was a selection, but if it was a mouse move, then it was a drag. But there will be old mouse events in the buffer that I need to discard.

chris-andrews22:10:32

Probably mixing and muting is the right approach for this. Thanks for all your input though @jr

thheller23:10:19

how anyone gets anything done in JS is a mystery to me ... the React codebase looks like complete chaos to me ... so glad we have CLJS simple_smile

richiardiandrea23:10:09

a question, does ClojureScript creates Namespace objects? in-ns returns nil on success