Fork me on GitHub
#clojurescript
<
2016-05-10
>
risto00:05:59

is there a way to introduce environment variables in clojurescript? ie dev vs prod variables

vinnyataide00:05:52

risto I guess when you enter a process there are ways to catch the vars. like *1 *2 so you can check which env you are and load the namespace of the correct env

vinnyataide00:05:27

that's how I would've solve it

risto00:05:26

@vinnyataide: How would you go about it more specifically? the issue is the ClojureScript is compiled into JS, so it needs to be passed into closure somehow, but I don't see any options to pass in environment variables

risto00:05:02

The only solution I can think of is having a separate externs file for dev and prod that exposes the same namespace, and including the right one for each

risto00:05:13

But it feels a little hackish

vinnyataide00:05:33

the problem with dev and prod should not be an issue for the app

vinnyataide00:05:39

just for the tooling

vinnyataide00:05:10

check leiningen if it doesnt have any way

vinnyataide00:05:40

only server and build tools care about env in my way of view

vinnyataide00:05:44

maybe I can be wrong

vinnyataide00:05:52

@risto now I'm having trouble understanding what reify stands for and those names in om like

om/ICheckState    om/IInitState 

risto00:05:05

Well, the issue I'm having might be solved in a nicer way

risto00:05:29

Basically I'm using figwheel to develop my app, but it runs a server that serves the websocket connection, but in prod I have no server (it's all client-based)

risto00:05:52

So if I want the fetch a relative path via ajax, figwheel will get the wrong path

superstructor00:05:18

how does one return equivalent of ^:export, which is a reader macro from a ClojureScript macro ? e.g.

=> (defmacro example [fn-name-expr] `(defn ^:export ~fn-name-expr [arg1# arg2#] true))
#'boot.user/example
=> (macroexpand-1 '(example foo))
(clojure.core/defn foo [arg1__6814__auto__ arg2__6815__auto__] true)

risto00:05:09

For example, I have the path /levels and /resources/public/js/src. In prod, it can fetch /levels without a server same-domain by just using the relative path ../../levels. In figwheel, it says localhost:3449/levels/... doesn't exist.

superstructor00:05:32

could I do this maybe ?

=> (defmacro example [fn-name-expr] `(vary-meta (defn ~fn-name-expr [arg1# arg2#] true) assoc :export true))
#'boot.user/example
=> (macroexpand-1 '(example foo))
(clojure.core/vary-meta (clojure.core/defn foo [arg1__6825__auto__ arg2__6826__auto__] true) clojure.core/assoc :export true)

risto00:05:20

To clarify, obviously there's a server that serves /levels, etc (the app itself), but what I mean is that it's not my server but a remote one that just serves files statically, so I can't hook figwheel to it directly

cky00:05:46

@superstructor: I'm given to understand that with-meta is the correct function to use.

cky00:05:14

You'd attach the meta to ~fn-name-expr of course.

superstructor00:05:12

@cky ok thanks I’ll try that simple_smile

vinnyataide00:05:47

@risto I'm wondering where you're going to run if you get no server to serve the cljs files

superstructor00:05:55

@cky: hmm but :export true appears to be on the fn not on the ~fn-name-expr ? and won’t using with-meta vs vary-meta overwrite other metadata ? (see snippet)

risto01:05:43

@vinnyataide: It's a simple browser game that requires no server (for now): https://github.com/Risto-Stevcev/sokoban

vinnyataide01:05:08

So this game could run as a native desktop app? or a website, anyways, I dont know anything about publishing apps in cljs, gotta read about that, awesome game btw

vinnyataide01:05:54

from a begginers perspective I'm impressed by the complexity of the code. I can't read most part of it because the logic is so functional

vinnyataide01:05:03

@risto you used this virtualdom lib. is it a more low level way to interact with the dom besides react wrappers?

risto01:05:00

I'm also a clojurescript newbie

risto01:05:29

Yeah, it's only slightly more low level. You need to create a wrapper for diff and patch, which react does under the hood.

risto01:05:53

I don't want to use React because I'm boycotting it's PATENTS clause (I know the ClojureScript community has a love affair with it)

risto01:05:10

It's a good library overall, I just have issue with their approach to open source

risto01:05:50

I would use snabbdom over virtual-dom because it's faster, but it wasn't in the CLJSJS package list. I'll probably submit a pull request to include it

fasiha01:05:28

@vinnyataide: regarding your first question—from what I can tell, the ClojureScript story on react/redux/graphql is still an open research problem. Om Next, re-frame (built on reagent), posh (built on reagent+datascript), rum (which is a wrapper to Om Pre + reagent, also by the datascript author) are all trying to figure out the best way to do all of these things. Some parts are more advanced than others in some of these libs. Rum has server-side rendering. Om Next has working graphql-style post-modern (i.e., not REST) client-server synchronization. Re-frame nails the redux story (it preceded Redux by several months, I suspect Dan Abramov read re-frame's famous readme in his sleep).

fasiha01:05:09

Probably, hopefully in a year or so, significant progress will be made towards holy grails.

fasiha01:05:00

Right now, plenty of people are making totally functional apps, but they're probably compromising on one aspect or another of the eventual paradise of web development we all seek.

vinnyataide01:05:07

@fasiha: what about subscriptions? does any of them cover it?

xcthulhu01:05:38

@vinnyataide: re-frame has subscriptions.

fasiha01:05:15

What @xcthulhu said: re-frame has subscriptions in the Redux sense

fasiha01:05:32

But not in the GraphQL backend<->frontend sense.

vinnyataide01:05:46

no component dependecy

xcthulhu01:05:08

Yeah. Orthogonal to these frameworks is sente, btw, which is a great library for delivery push notifications to clients.

sbmitchell01:05:31

I was wondering if the authors of reagent were considering moving to a declarative query syntax like om.next for components

sbmitchell01:05:44

I like that idea from om.next but I just dont like om in generl

sbmitchell01:05:54

I hope thats in reagents road map though

xcthulhu01:05:13

@sbmitchell: reagent is all about ratoms, it's a totally different paradigm

sbmitchell01:05:34

I suppose that is true

sbmitchell01:05:58

you could do something on the re-frame side as far as the subscription model then

sbmitchell01:05:09

perhaps reagent internally does not need to add these things

sbmitchell01:05:08

Seems like your subscriptions could be tailored to accept a graph ql syntax and you could have some fn to parse it and get data as you wish

sbmitchell01:05:12

not sure.. just spit balling

fasiha01:05:24

Reagent can probably be seen as a thin wrapper to react. It doesn't have post-react ideas like a central app db like redux/re-frame/posh. Which I think is good—let the bottom-most lib be unopinionated and let the layers on top be more so.

sbmitchell01:05:39

I agree with that

sbmitchell02:05:05

yea thinking more about that reagent wouldnt be the right place for that..the data model is a concern for the framework that deals with data

sbmitchell02:05:15

reagent components in general should be dumb as bricks

sbmitchell02:05:37

so re-frame is probably where this kind of thing would need to happen

xcthulhu02:05:51

@fasiha: The biggest sell of reagent (for me) is that, if you are disciplined, it's just hiccup. If you don't lean on React too much you can reuse the same code for server-side rendering.

vinnyataide02:05:06

What dont you like about om?

vinnyataide02:05:18

I really liked the david nolens talks

sbmitchell02:05:20

to be fair I did not give om a fair shot

sbmitchell02:05:27

I like david nolens talks for sure

sbmitchell02:05:39

hes a guy I look up too for his ideas and passion for front end

vinnyataide02:05:40

he semmed very sure of what he was building

sbmitchell02:05:17

I think if I was given a better story as to how to work with hiccup inside of om

sbmitchell02:05:20

I may have picked it up

vinnyataide02:05:37

there's a lib to work with hiccup

vinnyataide02:05:45

it translates to om

sbmitchell02:05:55

reagent was more accepting

sbmitchell02:05:00

for me anyway

sbmitchell02:05:11

and thats just what I work with now...so I have a bias

vinnyataide02:05:29

the thing i dont understand from om is those names

xcthulhu02:05:42

@vinnyataide: Om (especially om.next) will never be "just hiccup"

vinnyataide02:05:43

i dont know what they mean and their purpose

vinnyataide02:05:03

and the multimethod too

sbmitchell02:05:09

there were issues with om...so im kind of thankful I didnt go down that route

sbmitchell02:05:16

bc then id have to worry about moving to om.next

sbmitchell02:05:42

om at scale and having the data structure needing to map to the ui structure

sbmitchell02:05:50

thats why om.next models stuff as a graph

sbmitchell02:05:59

so cursors in om were terrible apparently?

sbmitchell02:05:10

and core.async being used everywhere was not great

vinnyataide02:05:21

thats so strange

sbmitchell02:05:26

nolen did mention this at conj that I went too

vinnyataide02:05:38

bec so many things use the concept of cursors

sbmitchell02:05:41

I think circlci had a good article about it

sbmitchell02:05:43

let me try find it

vinnyataide02:05:07

im from brazil so I can only see by youtube ;{

sbmitchell02:05:39

anyway..all the problems that did come about are being addressed in om.next

xcthulhu02:05:29

Eh, if I got a job at a clojurescript shop I'd use om.next if everyone else was.

sbmitchell02:05:58

our shop is probably looking for people simple_smile we are a clojure/cljs shop heh

sbmitchell02:05:03

but we are using reagent

xcthulhu02:05:39

I use reagent too for my hobby project.

sbmitchell02:05:22

pretty hard to find clojure devs and then clojure devs that dont mind working in clojurescript

xcthulhu02:05:46

Just today I'm getting ready to release a cryptography I've been writing in clojurescript/clojure for doing ECDSA

xcthulhu02:05:15

This stuff is insanely easier in Clojure than ClojureScript

xcthulhu02:05:33

I found a bug in goog.math.Integer in the course of this crazy project

vinnyataide02:05:34

I still am not understanding the presence of those "directives" I think it is, looks like an interface

om/ICheckState    om/IInitState 

xcthulhu02:05:23

I'm really sad to say this, but you can't really rely on the google closure library

vinnyataide02:05:30

I mean, not awesome to find a bug

xcthulhu02:05:41

Also, it screws up converting UTF-8 to byte-code

xcthulhu02:05:02

Lesson: test your code

vinnyataide02:05:42

Yeah I have some criteria about testing necessity but low level stuff is really in the critical part for testing

vinnyataide02:05:38

I dont mind cljs mainly because when we live with js this is one of the best ways to go, besides elm

vinnyataide02:05:50

I really like the lisp thing

vinnyataide02:05:53

really got me

vinnyataide02:05:02

never saw before

xcthulhu02:05:10

Dead code elimination

vinnyataide02:05:40

dart has suffered from that

xcthulhu02:05:49

I have some contract work doing cryptography in Scala/Scala.js coming up

vinnyataide02:05:54

I was a dart dev for some time, in the angular golden era

xcthulhu02:05:06

I'm nervous about the whole thing

vinnyataide02:05:20

scala is scary

xcthulhu02:05:25

Tooling around Scala.js is non-existent

vinnyataide02:05:31

like go or rust

xcthulhu02:05:53

Eh, before I was a clojure programmer I programmed Haskell, and before that I was just a mathematician doing computer assisted proofs, Scala doesn't scare me.

vinnyataide02:05:17

install eclipse and youre good to do 💩

vinnyataide02:05:52

yeah haskell is beautifully scary

xcthulhu02:05:07

It's beautifully impossible to get anything done in, yeah.

xcthulhu02:05:21

We're moving /offtopic, btw

vinnyataide02:05:29

I gotta finish this datalog tutorial but the interpreter is broken ❤️

vinnyataide02:05:59

its showing some regex msg error

fasiha02:05:41

@vinnyataide: uhh yeah, that's very frustrating. But that tutorial only covers queries, not transactions, which are important too. There's a crippling dearth of beginner tutorials stuff but check the last couple at #C07V8N22C for some reasonable reading material.

fasiha02:05:39

Let me actually write a gist on how to get http://learndatalogtoday.org working in a local repl. Datascript runs on JVM too, so I'm just doing all my exploration in JVM repl

vinnyataide02:05:20

dangit im reading all those tutorials and getting all dizzy, maybe I need to learn all those cljs special characters

fasiha02:05:53

Oh. Datascript/Datomic have a ton several special datascript/datomic-only characters that aren't Clojure-specific 😞

fasiha02:05:23

Datascript/Datomic are dizzifying af

xcthulhu02:05:06

@fasiha: I've thought about using DataScript, but I'm scared that it's too heavy. How much does it add to your javascript payload in production?

xcthulhu02:05:17

Some apps it doesn't matter I guess.

fasiha02:05:21

Sorry I have no idea. If it saves me from having to write REST endpoints and two separate queries (frontend vs backend), I'll be happy to pay in page load time. Provided it doesn't drive me to drink.

vinnyataide02:05:20

thanks fasiha

vinnyataide02:05:45

Im looking at the symbols and some arent clojurey

vinnyataide02:05:40

interesting to say that there is another realm of languages, is SQL a logic lang too?

xcthulhu02:05:17

SQL was a simplification of datalog (a simplification of prolog). SQL did not originally have the power to do recursive queries like datalog could, but after many epicycles they are equally powerful as query languages go.

xcthulhu02:05:25

Since you can do subqueries in SQL

cky02:05:45

@superstructor: Does

(defmacro example [fn-name-expr] `(defn ~(with-meta fn-name-expr {:export true}) [x#] x#))
work for you? I don’t have a good macro setup for ClojureScript at the moment but some manual expansions suggests it should work.

superstructor02:05:52

@cky thanks again, I think you are right. That looks like it could work, I’ll need to compile everything and look at the output to double check.

vinnyataide02:05:07

oh nice insight

cky02:05:23

@superstructor: Cool, lemme know how it does. That seems to replicate your original code most faithfully.

cky02:05:35

(i.e., attaching the meta to the symbol being defined, rather than to the defined result)

superstructor02:05:43

@cky yep will let you know, it just needs to be compatible with this when it eventually reaches emit* https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L636

nicoschneider07:05:51

Does anybody have experience in wrapping koa.js in cljs? Planning to write my first side project in cljs and i'd like to go with a node api server. tips?

risto11:05:07

@nicoschneider: Doesn't koa use generators? I don't think clojurescript supports those, but I might be wrong about that

toxi12:05:02

hi people! quick question, can somebody pls point me to examples how to use js* from within a macro pls? i just can't get it to work and there're close to zero docs.. am aware this is not to be used directly, but am prototyping some ideas and am slowly despairing... the whole cljc changes made macros in cljs even more confusing - thx!

dnolen13:05:15

@toxi .cljc didn’t change anything about macros at all

dnolen13:05:33

but it does seem some people have been confused by that fact

dnolen13:05:22

far as js* you’ll probably just want to look at the core macros file for examples

dnolen13:05:46

I think the main trip up around js* is that if you’re going to generate an expression you need to make sure it’s js* and not cljs.core/js*

dnolen13:05:36

for example

toxi13:05:40

@dnolen oki, thx - i did take a look & this is where my confusion stems from (/src/main/clojure/cljs/core.cljc)

toxi13:05:09

@dnolen oh, just saw your link - that's the same example i've been using... simple_smile

dnolen13:05:09

using core.cljc as an example of something you can accomplish yourself

dnolen13:05:14

it cannot be done

dnolen13:05:42

it’s full of special cases for bootstrap and has special compiler support

dnolen13:05:09

so I wouldn’t try to use it as any kind of reference about .cljc

toxi13:05:28

@dnolen - ha but your hint re js* vs cljs.core/*js very much helped... just solved it like this: (defmacro foo [x] (let [js 'js*] (js (str "/ " x " */"))))`

toxi13:05:37

@dnolen: merci beaucoup! simple_smile

dnolen13:05:41

no problem

toxi13:05:24

@dnolen: btw. trying to create a custom protocol mechanism for emscripten fns...

dnolen13:05:13

@toxi do you mean - make emscripten fns extendable to protocols?

toxi13:05:53

@dnolen: yes, clojure types will simply be wrappers around pointers and then delegate to asm.js fns

dnolen13:05:46

that sounds cool!

toxi13:05:15

@dnolen: will keep you posted...

fasiha14:05:17

Oh gods, Elm removed FRP and added subscriptions: http://elm-lang.org/blog/farewell-to-frp </minor offtopic sorry>

dnolen15:05:31

@fasiha that’s interesting

nha16:05:23

Yes - it is the top story in HN right now: https://news.ycombinator.com/item?id=11667523

bhauman16:05:44

@risto: in reference to you server path issue, I think your slight miss-understanding is that there is a server even with a static site. So if you want prod to match up with dev you will need a development static server with the same path setup as production.

bhauman16:05:18

so in your case I would run a dev static server separate from figwheel that delivers files the same way your production setup will. Figwheel will automatically connect to the development env.

risto17:05:35

@bhauman: Yeah, I realized that yesterday night when I was talking about how there is a server that's servering the files but it's not mine. I'll just change it to just use the lein static server and hook it up to figwheel

risto17:05:25

I'm glad though that I found out that there is a way to do something like lein-environ for the frontend. It might come in handy someday, who knows

vinnyataide18:05:05

that is awesome, in the outside mainstream world I dont really focus on the build tools to manage my production. I just manage through an outside script that update some files

vinnyataide18:05:24

Oh shit bhauman and dnolen. I am having a nerdgasm right now.

pataprogramming19:05:37

Anyone using CIDER + boot-cljs-repl? I'm getting a NullPointerError. Works fine when running (start-repl) from a CLI boot-launched REPL, but not after a cider-jack-in.

pataprogramming19:05:43

Are there some known versions that I should downgrade to? I'm running on CIDER 0.13.0-SNAPSHOT at the moment, and adzerk/boot-cljs-repl-0.3.0.

risto19:05:22

@vinnyataide: Yeah, I'm glad that they're approachable. The ClojureScript community seems pretty awesome

vinnyataide19:05:06

why is cider asking to install 0.13.0-SNAPSHOT if the github version only goes till 0.12.0

pataprogramming19:05:06

MELPA vs. MELPA stable.

pataprogramming19:05:38

It's extremely annoying to get an Emacs setup that mixes packages from two repositories...it will always try to grab the highest version number, unless it's pinned.

pataprogramming19:05:48

I haven't had any problems running off of MELPA (non-stable) for the last six months, but it's been pretty bad at various points in the past.

vinnyataide19:05:18

Im moving to melpa stable now since I cant dowload cider 13 in my .lein conf

pataprogramming19:05:38

Recent versions of CIDER will automatically inject the deps, so you no longer have to maintain them in your profile.

pataprogramming19:05:28

So, you can try just removing the CIDER deps (including refactor-nrepl) from your Lein profile, and doing a cider-jack-in.

pataprogramming19:05:53

CIDER 0.13.0-SNAPSHOT has been working great for me. But I might have to downgrade if I can't figure out this cljs REPL issue.

vinnyataide19:05:18

.you mean the dep right? not the plugin

pataprogramming19:05:56

The cider-nrepl plugin? It will be automatically injected.

pataprogramming19:05:36

I used to launch REPLs by hand for more control. No more...since I switch to using jack-in, the dependency injection keeps all the versions in sync.

underplank23:05:48

Hi all, im trying to build a react-native app using re-natal and reagent. 1) is there a channel somewhere for this 2) im having some issues with node finding a library that it thinks it wants.

underplank23:05:26

worked it out. spelt the library name wrong 😞