Fork me on GitHub
#clojurescript
<
2016-05-26
>
sbmitchell01:05:53

@vinnyataide: you can use the .. in clojurescript as well. I found it quite handy to use when working with d3 specfically

bojan.matic11:05:29

has anyone used postcss with figwheel? how could i integrate that into the sass build?

rauh12:05:54

Just created this and think that some people might find it helpful: https://github.com/r0man/sablono/wiki/Optimization-Tips

anmonteiro12:05:41

only do this if your (foo) function call returns React elements.

rauh12:05:58

It can also return a list of elements actually.

anmonteiro12:05:01

shouldn’t this read “if your function call doesn’t return React Element” ?

anmonteiro12:05:26

or I wonder why you’re type-hinting a React element with ^String

rauh12:05:34

Well it could return hiccup data, then it needs interpretation.

rauh12:05:03

Well, because the ^String type hint is the only one accepted by sablono. It's a "hack" I suppose

anmonteiro12:05:04

other than that, seems really helpful

rauh12:05:09

But it works very well 🙂

rauh12:05:35

I'll clarify it that it won't actually need a string, even though it's a String type hint

risto14:05:52

@mattsfrey: I added https://github.com/caolan/async to CLJSJS a little while ago, so you can use that if you are just getting your feet wet with ClojureScript

risto14:05:44

However, you can to async.serial fairly easily with channels (using <!), and @darwin showed me how you can do async.parallel with channels

mattsfrey14:05:10

oh really, care to share?

mattsfrey14:05:16

http://www.lispcast.com/core-async-browser-motivation the final example in this article was about as close as I’ve got to that

risto14:05:36

^ See this link to the archived conversation ^

risto14:05:18

I think I'll add a blog post on this (I'll definitely give @darwin credit for the async part)

risto14:05:21

@dnolen: I definitely feel like the JS library async.serial and async.parallel patterns are so common that there should be an explanation in the ClojureScript wiki on how to translate those patterns with core.async. Would you be open to (me or someone else) adding that to the main wiki?

mattsfrey14:05:56

^would be super useful

underplank16:05:00

qq are there any clojurescript libs for connecting and performing SQL queries? DO any of the clojure ones such as yesql support clojurescript as well?

andrewsuzuki16:05:09

for what? running clojurescript on node? or websql?

underplank16:05:17

Hmm.. I’ve had a bit more of a think about it and im running tests in phantomjs, hitting a backend that I want to clear out. But running in phantomjs makes that a little tricky 😉

underplank16:05:30

So I think I need to think about how to do this a bit more.

underplank16:05:59

I dont want to have a clear all in my API. But I need someway to reset the state of my backend when running these tests.

tdaudelin16:05:56

Why not mock your backend?

underplank17:05:45

tdaudelin: I would prefer not to, just because I prefer to have as little mocking as possible. I control both front end and backend so can get really good confidence about if both work together by testing them together

underplank17:05:02

And its a side project so I like to make it hard for myself 😉

curtis.summers17:05:11

@underplank I've considered adding Clojurescript support to HugSQL, but have not yet gotten around to it. See https://github.com/layerware/hugsql/issues/14 If this is something that interests you, I would appreciate your input in that github issue on what platforms are using in clojurescript w/ a relational DB and what underlying JS database libraries would be appropriate for building on top of. Thanks!

underplank17:05:19

curtissummers: oh thanks. I’ll check it out, but have to admit im probably not the best person to ask 🙂 I dont do clojure or clojurescript in my day job unfortunatly. so im just playing around with some side projects.

underplank17:05:11

it does look like the nodejs library for postgres is called ‘pg’ if that helps 🙂

underplank17:05:01

Im using lein doo as the test runner, does anybody know if there are hooks for it to run commands before the test runner starts?

underplank17:05:18

bensu: I guess I could just ask you if you are around. Are there any hooks in lein doo for running a process before the test runner?

bensu17:05:42

there are none

bensu17:05:08

but a recent PR needs hooks after, and if I go down the hook path I might as well add them on both sides

bensu17:05:33

IMO if your plugins are getting to complex, it is time to use boot.

bensu17:05:03

what do you need the hook for?

pesterhazy18:05:14

Today I learned: with browserify, require("foo") may work but var m="foo"; require(m); will not

pesterhazy18:05:18

Is it a general requirement that javascript require functions always take a static string rather than a variable?

risto18:05:44

@pesterhazy: For ES6 import statements, they're usually resolved before any code is run. I'm not sure if browserify works the same way though

pesterhazy18:05:19

ES6 import is just require under the hood, right?

risto18:05:37

Well, I'm assuming you're talking about Babel

risto18:05:04

Babel uses the ES6 module syntax, but you have to choose what you use under the hood. Most use browserify, but babel also offers generic AMD, UMD, and CommonJS module systems

risto18:05:26

the underlying module implementation is something you chooose for babel

pesterhazy18:05:29

very intresting

risto18:05:44

For actual ES6, it'll be however the browsers decide to implement it

pesterhazy18:05:14

I've lost track of those many competing bundling solutions (last I worked with was browserify, a few years ago)

risto18:05:32

There's really only two that you can really take seriously: Webpack and Browserify

pesterhazy18:05:55

unfortunately, I have to work with a third one, i.e. the react native packager

risto18:05:15

ah I don't know about that one. I guess I also forgot to mention Typescript's module system, which is also popular

risto18:05:43

Webpack works nicely with React because it has hot module reloading

pesterhazy18:05:51

which is also completely undocumented, which is why I'm trying to understand what is assumed as given in js land these days

pesterhazy18:05:33

yes, but react-native developer decided against it (webpack wasn't fast enough for them)

pesterhazy18:05:51

so with webpack, can you "dynamically" require modules?

risto18:05:11

yeah, so if you change something in a module, say a React component, you can see it live update in your running code

risto18:05:18

kind of like a semi-figwheel type of deal

pesterhazy18:05:35

sorry, what I meant was, require a variable rather than a string

pesterhazy18:05:49

or does webpack also "statically analyze" (?) the js during compilation?

risto18:05:19

did you try it with plain old browserify?

risto18:05:58

or was it Babel + browserify?

pesterhazy18:05:42

plain browserify

risto18:05:50

I know why it's not working with plain browserify

risto18:05:10

because browserify is compiled, so it doesn't evaluate runtime code, which is what that is

risto18:05:23

if you tried that in NodeJS it would work

pesterhazy18:05:43

yes, it works in node but not in the browser

pesterhazy18:05:02

(in the snippet it falls back on node's global.require if it exists)

pesterhazy18:05:49

I'll try it with webpack

risto18:05:55

what are you trying to do?

pesterhazy18:05:09

well basically

risto18:05:09

if the variable is only a finite set of states, you could probably use a switch statement

pesterhazy18:05:57

for boot-react-native I'm trying to intercept calls to goog.require and reroute them to react-native's require function

risto18:05:33

I don't think you could use Webpack for that either

risto18:05:42

I'm pretty sure that's compiled also

pesterhazy18:05:47

no, I won't use webpack

risto18:05:48

you would need to use a runtime module system, like RequireJS

pesterhazy18:05:08

I'm just trying to grok what the expectations on a module system are

martinklepsch18:05:32

@pesterhazy: figwheeel et al all patch goog.require maybe that can provide some inspiration

pesterhazy18:05:35

so RequireJS is a "runtime" module system because it can asychronously load js dependencies, right?

pesterhazy18:05:21

@martinklepsch: good idea. Though the patching part is already done (it worked with react-native 0.19 but now fails with version 0.26)

risto18:05:26

yeah it's not complied AFAIK, I haven't used it in years

risto18:05:47

but you have to wire the actual modules yourself

risto18:05:09

you might be better off just following @martinklepsch and seeing the figwheel implementation

pesterhazy18:05:19

well you can require things at runtime with the react native packager

pesterhazy18:05:41

If I understand it correctly, you have to pass it a module id

risto18:05:42

for RequireJS, you need to actually wire up (wrap) the module with the requirejs syntax. From what you're saying, I think you want it to be generic and do it dynamically (not wired up statically and manually)

pesterhazy18:05:11

what do you mean by wiring up?

risto18:05:22

if you have file "a", and you want it to depend on file "b", you need to write the AMD style syntax (dependency injection) into file "a" and file "b"

risto18:05:35

you have to write it into your modules

risto18:05:58

if you're using an outside library, you have to use requirejs to compile it into a shimmed library so it can support AMD syntax

pesterhazy18:05:38

it's all terribly confusing

risto18:05:13

I would just rip off figwheel

pesterhazy18:05:18

webpack produces a warning if I try require(variable):

the request of a dependency is an expression

risto18:05:35

yeah, generally dependencies are statements

pesterhazy18:05:51

so there's the expectation that the argument to require must be a string

risto18:05:41

otherwise resolving dependencies might be undecidable

risto18:05:45

probably is undecidable

risto18:05:03

you might save yourself some frustration by trying to do the same thing with react-native's module system

risto18:05:09

im pretty sure you couldn't do it there either

risto18:05:13

might be wrong though

risto18:05:37

actually it is* undecidable

pesterhazy18:05:30

well, it used to work with a previous version of the packager. My hope is that it'll work as well with the new packager.

pesterhazy18:05:08

I'm guessing there must be a list of dependencies somewhere, a mapping of moduleId -> module

pesterhazy18:05:26

so if I require at runtime I need to specify the correct moduleId

risto18:05:27

it might work, i would just try it. But in general it's not allowed probably because it's undecidable

risto18:05:05

I would probably avoid that level of hacking and just make a domain-specific solution that's less generic

risto18:05:18

because it could break at later versions of whatever libraries you're using

pesterhazy18:05:14

it's hacky but unfortunately necessary for good interactivity using react-native code reloading

risto18:05:44

just make sure you know what you're doing

risto18:05:30

alternatively, what you could do it use a JS parser and statically analyze the code, and then wire up the dependencies at "compile time"

risto18:05:48

compile-time linking

risto18:05:10

that way it would be generic and you could still use statements

risto18:05:18

for modules

pesterhazy18:05:19

yeah I guess that's what the react-native packager does, or at least used to do

risto18:05:20

static strings*

pesterhazy18:05:36

it basically regex'ed the hell out of your code

risto18:05:44

that's hackish

risto19:05:01

javascript is turing-complete, regex isn't powerful enough to handle that

risto19:05:59

it probably wrote a really hackish form of a TM parser, not unlike how a lot of newer coders will write a pushdown automata to parse HTML using regex, not realizing that they're writing it because HTML is a context-free grammar and can't be parsed with regex alone

risto19:05:11

i would just use a proper parser like esprima

pesterhazy19:05:39

yeah but I'm not going to go down that rabbit hole 🙂

m0smith19:05:41

Is there a tutorial using cljs and nodejs for CLI script tools?

jcromartie20:05:45

I want to add Clojurescript to my Compojure web app.

jcromartie20:05:31

I want to have clojurescript sources compiled to resources/public/js/main.js and include this from a .html file like <script src="/js/main.js">

jcromartie20:05:44

the clojurescript compiler produces paths like this

jcromartie20:05:30

document.write('<script src="resources/public/js/cljs_deps.js"></script>');

jcromartie20:05:58

this won't work, unless it's src="/js/cljs_deps.js" instead

jcromartie20:05:21

now to be fair I don't know how the Clojurescript compiler could possibly know this...

jcromartie20:05:24

I have :output-dir "resources/public/js"

jcromartie20:05:59

Thanks #C03S1L9DN! That worked!

wildermuthn23:05:51

Any thoughts on when clojure.spec might arrive for ClojureScript, if we’re looking at days/weeks/months? I don’t see it in the CLJS JIRA board, but saw some comments on HN saying it wouldn’t be a cljc implementation.