Fork me on GitHub
#clojurescript
<
2017-02-23
>
mobileink00:02:50

well here's one problem, which i expect we all recognize: we end up with defx for a thousand different xs. i don't know what to do about it, my own lib has it's own defx stuff. but it doesn't seem like a good thing.

adambros00:02:01

@mobileink i’ve usually written my defx macros with a x* function that does the work, that way you can write your defx+y macro by just composing their x* & y* functions

adambros00:02:05

well… assuming they can compose like that, some defx macros may need to emit incompatible code with other defx's

qqq04:02:45

DevTools failed to parse SourceMap: httpsL//localhost:8000/main.out/cljsjs/showdown/development/showdown.js.map

qqq04:02:50

I don't have a a showdown.cljs

qqq04:02:56

what is showdown.js / showdown.js.map and why do I want it?

not-raspberry04:02:50

Something from cljsjs has it.

qqq04:02:36

cljsjs is not a package, it's part of the output path I chose

qqq04:02:40

it should be renamed "out"

qqq04:02:23

oh n/m, cljsjs is a package

qqq04:02:25

I'm an idiot

not-raspberry04:02:12

Technically, a package repo. And a namespace.

Jon07:02:11

I tried to run js code compiled from ClojureScript in Weex, and (pr-str {}) returns [object Object]. In theory, Weex is using V8. But is there any chance that pr-str returns [object Object] in V8?

thheller09:02:39

@jiyinyiyong it would be much simpler to debug with :simple optimizations. but my guess would be that console is different in Weex. It is not an object natively support by V8. Node.js provides a different one from the V8 embedded in Chrome.

thheller09:02:58

what happens if you (js/console.log "foo")

dsapoetra10:02:43

Hi everyone, is there anybody who generated csrf-token in clojurescript? In SPA style, I’m new at SPA style, I use ajax to send data from client (cljs) to backend (pedestal), and I don’t have any idea on how or best practice to do it, Been googling and found : https://gist.github.com/coyotespike/aca29bdeca1eea1e8648 But that doesn’t seem to work on my machine Any advice/help will be appreciated, thank you in advance!

not-raspberry10:02:17

@dsapoetra you normally generate the token on the server side, in Clojure.

not-raspberry10:02:58

Do lein new luminus example and analyse that. It works.

dsapoetra10:02:00

@not-raspberry how do we merge it in ajax request from client-side(cljs) to backend?

not-raspberry10:02:59

You normally add some middleware. Really, check that luminus template out. It's in src/cljs/<project name>/ajax.cljs. On the clojure side it also uses ring.

not-raspberry10:02:44

Xhr libraries in clojurescript normally have some middleware for that

risto12:02:22

what's the convention to provide specs for multimethods?

risto13:02:06

oh i see, it's multispec

alexmiller13:02:03

No, multispec is to create an open spec

alexmiller13:02:18

At the moment, spec doesn't work with multimethods

risto14:02:54

is there a way to check if instrument is enabled?

alexmiller15:02:49

publicly, no

alexmiller15:02:01

but there is a private var at clojure.spec.test/instrumented-vars

alexmiller15:02:17

@#‘clojure.spec.test/instrumented-vars should let you snoop

Jon17:02:28

@thheller you are right, I'm trying it.

Jon17:02:32

I heard from their developers that they freeze global objects for performance and security purpose.

Jon17:02:58

And my js code is throwing error TypeError: Cannot assign to read only property 'toString' of [object Object]

Jon17:02:43

Very likely that the prototype in goog.math.Integer.prototype.toString = function() is broken

Jon17:02:10

And somehow the console in the debugger handle it silently, so it calls native toString method, then I got ({}).toString() which is exactly [object Object].

Jon17:02:34

Guess Weex and ClojureScript are just conflict

thheller17:02:40

@jiyinyiyong it shouldn't be too hard to get this working properly. If you are compiling with :target :nodejs the bootstrap that happens expect to be running node, which you are not.

thheller17:02:16

try it without the clojurescript

Jon17:02:34

I don't get it.

thheller17:02:57

var MyType = function() {}; MyType.prototype.toString = function() {};

Jon17:02:07

Did you mean I should add :target :nodejs in my compiler options?

thheller17:02:30

if that doesn't work you are out of luck I guess

thheller17:02:47

no sorry, forgot you were using optimized output

Jon17:02:50

I'm inspired, trying if your snippet will work

thheller17:02:05

are there some docs about the weex runtime?

thheller17:02:35

only saw docs for the JS parts you are supposed to use but no details about the runtime

Jon17:02:54

js

var My = function() {}

My.prototype.toString = function() {
  return 'My Thing'
}

var a = new My

console.log('result:', a.toString())

Jon17:02:14

I wrote this script, and it works in Node.js, but fails in Weex

Jon17:02:21

confirmed the problem

thheller17:02:42

yeah so not CLJS related

Jon17:02:46

just CojureScript is using that feature by default, and someone removed it.

thheller17:02:18

well not even ClojureScript, the example you linked of from the google closure lib

Jon17:02:22

but I still feed bad that ClojureScript is depending on it. I barely use such thing. And I'm actually happy with my life powered up by Webpack.

thheller18:02:33

well I kinda question the fact that they disallow overriding toString, there are gonna be tons of JS libs that expect to use that

thheller18:02:00

seems like a bad idea

Jon18:02:25

They said they are reusing the same Weex instance in Android and iOS, but found problems, even memory leaks, which are caused by strange things on global objects..

Jon18:02:49

/**
 * Freeze the prototype of javascript build-in objects.
 */
/* istanbul ignore next */
export function freezePrototype () {
  Object.freeze(Object)
  Object.freeze(Array)

  Object.freeze(Object.prototype)
  Object.freeze(Array.prototype)
  Object.freeze(String.prototype)
  Object.freeze(Number.prototype)
  Object.freeze(Boolean.prototype)

  Object.freeze(Error.prototype)
  Object.freeze(Date.prototype)
  Object.freeze(RegExp.prototype)
}

Jon18:02:56

kind of...

thheller18:02:37

yeah no idea, looks questionable to me. can't think of a simple way to work around it as many things in closure have toString fns

Jon18:02:23

giving up and going to bed.

Jon18:02:10

maybe my friends from Weex team will see my messages and give me advices, like never use ClojureScript, still cool...

thheller18:02:56

just show them the minimal JS example

thheller18:02:29

they are going to run into JS libs that try to do that eventually 😉

thheller18:02:18

@jiyinyiyong just had an idea, write a Closure Compiler pass that removes all .prototype.toString assignments

thheller18:02:50

that would actually be really simple, well Java is involved so not that simple but still doable

Jon18:02:41

Sound much harder than altering code in Weex 😛

binliu4clojure20:02:38

Dumb question: what is the difference between clojure and clojurescript?

7h3kk1d20:02:51

Clojure targets the jvm clojurescript targets javascript

7h3kk1d20:02:03

So Clojurescript is useful for the browser or if you want to interop with node.js

binliu4clojure20:02:35

are they the same syntax?

7h3kk1d20:02:04

Those are some differnces

binliu4clojure20:02:53

can i understand as clojure is more targeting cloud computing, while clojurescript is more for web dev front end and server?

7h3kk1d20:02:48

Clojure runs on the jvm so the jvm runs on lots of servers so I wouldn’t say clojrue isn’t for cloud. Anywhere you would use java you can use clojure. Also node.js is used in AWS Lambda so you could use clojurescript there which would be cloud

7h3kk1d20:02:58

I would say that clojurescript is more for the browser would be accurate.

7h3kk1d20:02:14

Lots of people do clojure backend clojurescript frontend.

7h3kk1d20:02:21

But it’s more about your target environment.

binliu4clojure20:02:16

I see.. thanks for the detail explanation!! clojure is for java, and clojurescript is for javascript....

binliu4clojure20:02:59

what is the story/motivation of the invention of clojure/clojurescript?

7h3kk1d20:02:33

This talk can probably explain why better than I can https://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

7h3kk1d20:02:02

Which came later

binliu4clojure20:02:11

Great! I will watch them!

rgdelato20:02:34

are there any good resources for learning how dependencies work in ClojureScript? I would ideally like to get to the point where I can port over an npm package (which uses other npm dependencies) for use in ClojureScript

7h3kk1d20:02:09

That’s all I know.

andrea.crotti21:02:42

how do people normally run multiple clojurescript projects at the same time?

andrea.crotti21:02:54

I mean you can change the figwheel port in the settings

andrea.crotti21:02:16

but it would be even nicer if it would just try the next port if 3449 is already busy

andrea.crotti21:02:20

otherwise I could always just use an env variable so I can change it more easily without touching the code

not-raspberry22:02:39

I have 16G of ram and spin many figwheels.

not-raspberry22:02:17

If you have many cljs targets in 1 tree, then lein profiles come handy. lein with-profile

Oliver George22:02:29

@andrea.crotti It's pretty rare that I need that. Different ports for both figwheel & nrepl would be a reliable solution.

andrea.crotti22:02:50

another question, this variable in cider `cider-cljs-lein-repl is a variable defined in ‘cider.el’. Its value is "(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))" `

andrea.crotti22:02:21

defaults to that, however various projects suggest to use this instead

andrea.crotti22:02:21

"(do (user/run) (user/browser-repl))")

andrea.crotti22:02:48

if I understand correctly as long as I use figwheel this second form should always work?

uwo22:02:46

I’m walking my state atom to strip it of non-cljs constructs e.g. goog listener keys etc. I was hoping I could differentiate with type but that doesn’t seem to cut it. any suggestions?

hlolli23:02:59

what meaning does == have in clojurescript when (= 1 1.0) returns true anyway?

jr23:02:13

1 and 1.0 are identical in javascript

fabrao23:02:03

Hello all, how do I call fade from :

var MaterialUIUtils = {
    colorManipulator : {
        convertColorToString : function() {},
        convertHexToRGB : function() {},
        darken : function() {},
        decomposeColor : function() {},
        emphasize : function() {},
        fade : function() {},
        getContrastRatio : function() {},
        getLuminance : function() {},
        lighten : function() {}
    }
};

jr23:02:08

(js/MaterialUIUtils.colorManipulator.fade)

jr23:02:28

that's probably the most straightforward way

fabrao23:02:55

material-ui.inc.js:35686 Uncaught TypeError: Cannot read property 'charAt' of null

fabrao23:02:51

(.-colorManipulator js/MaterialUIUtils)?

fabrao23:02:09

after that, I can´t figure out

jr23:02:15

does fade take args?

anmonteiro23:02:29

@hlolli cljs.core/== is much faster than cljs.core/= for numbers

anmonteiro23:02:49

the fact that 1 === 1.0 is just a JS quirk

hlolli23:02:58

ok nice, good to know! I need speed so that's why I asked

anmonteiro23:02:25

cljs.user> (time (dotimes [_ 1000000] (= 1 1)))
"Elapsed time: 206.890000 msecs"
nil
cljs.user> (time (dotimes [_ 1000000] (== 1 1)))
"Elapsed time: 1.150000 msecs"
nil

hlolli23:02:56

lt and gt are also equally fast, wonder what slows = down so much, since its comparing floats to integer like they are euqal (like ==).

hlolli23:02:33

ok, this made me realize (= nil) => true, I should overcome my fear of reading the cljs source code.