Fork me on GitHub
#clojurescript
<
2017-01-06
>
emccue00:01:37

This is my current build config

emccue00:01:08

cl.js is just a file with "alert("Loaded");" and the externs file is just blank. It is required in my code, but it isnt loading still

joshjones00:01:17

why does this work:

(def lg js/console.log)
(lg “Hello”)  ; prints “Hello” to the js console
and this does not:
(def get-el js/document.getElementById)
(get-el “elementname”)  ; results in TypeError: Illegal invocation

potetm00:01:54

this? Just a guess.

potetm00:01:58

Cljs fns are invoked with .call with a null this by default.

potetm01:01:04

Yes. It's this.

potetm01:01:36

(.call get-el js/document "app")
=> #object[HTMLDivElement [object HTMLDivElement]]

joshjones02:01:48

thank you @potetm -- I suppose after a long day I was subconsciously too lazy to do a google search lol

potetm02:01:08

@joshjones 🙂 Glad I could help.

jfntn05:01:45

Can this difference in behavior be relied upon or is it an implementation detail that could change in the future?

#?(:cljs
   (assert (identical? "ab" (str "a" "b")))
   :clj
   (assert (not (identical? "ab" (str "a" "b")))))

joshjones06:01:53

well, they're different for obvious reasons -- javascript really can't change its identity method, and clojure uses a StringBuilder to concat (str "a" "b"), and so it's highly unlikely (str "a" "b") will ever be the same object as "ab" in clojure. But it's not really something I'd want to rely on. -- why do you need to check for identical? instead of simply =? @jfntn

jfntn07:01:39

@joshjones: was looking at potential optimization for some string algorithms in our front end

rauh07:01:47

@jfntn This gives true FYI: (identical? "ab" (.intern (str "a" "b")))

jfntn07:01:56

@rauh: ah interesting, thanks

Pishty10:01:37

hello guys, not sure if this is the right channel but i was wondering if anyone had example code that uses react-native-drawer with with reagent

Pishty10:01:06

cljsrn, sorry guys

kim012:01:40

I’m confused about cljsjs .. and why it wouldn’t be needed when running on nodejs

juhoteperi12:01:21

@kim0 When running on Node, you don't use advanced compilation so you don't need externs from Cljsjs, and you might want to use npm packages directly

kim012:01:20

Why is advanced compilation not used ?

juhoteperi12:01:20

@kim0 Because there is no need to concatenate files for HTTP and because file size doesn't matter that much with Node apps (at least when running on server)

kim012:01:51

does that mean that google’s closure compiler isn’t used at all ?

kim012:01:24

Alright thanks!

scaturr13:01:46

Does anyone have some pro tips on making library code “safe” in ClojureScript? For example: say I have a blob function like so:

(defn blob
  "Converts a data-url into a JS Blob. This is useful for uploading
   image data from JavaScript."
  [data-url]
  (-> (re-find #"^data:([^;]+);base64,(.*)$" data-url)
      rest
      decode
      uint8
      make-blob))

scaturr13:01:09

Do you just let errors go through if the code is used like (blob 42)?

scaturr13:01:41

instead of (blob “data:image/png;base64,hi")

scaturr13:01:23

just use pre conditions?

scaturr13:01:10

thanks for confirming @martinklepsch 🙂

potetm13:01:33

So I wrote a thing I thought the people here might find useful: https://github.com/potetm/tire-iron

potetm13:01:58

Would love to hear feedback on it if you try it out!

pesterhazy14:01:14

@potetm looks interesting

pesterhazy14:01:22

so it's a third alternative besides figwheel and boot-reload?

potetm14:01:16

Yeah. Plus it does namespace clearing and macro reloading.

potetm14:01:49

So it's more similar to the functionality of tools.namespace.

potetm14:01:06

Plus it's not tied to a particular build tool.

potetm14:01:10

So those are the things that differentiate it. But at the end of the day yeah: It's a figwheel/boot-reload alternative.

robert-stuttaford14:01:07

i love that you built this potetm 🙂 curious: does figwheel do something that makes this approach unfeasible?

robert-stuttaford14:01:17

or is it possible for figwheel to meet all the same goals?

robert-stuttaford14:01:32

i’ve wondered about applying a true reload to cljs for a while

robert-stuttaford14:01:17

since it’s so good in jvm. but … the browser kinda comes with one already so i never bothered pursuing 🙂

potetm14:01:49

I know figwheel's had a ticket out for namespace unloading for some time. But they're going to have a messaging problem, because a lot of their previous messaging was centered on the fact that you can safely store your state in a defonce, which will no longer be the case.

robert-stuttaford14:01:12

aha. yes, that is a pretty major difference

potetm14:01:28

Yeah, the refresh button + autobuild works alright. 🙂 Keeping your state around is nice, and having that turnaround be slightly faster is also nice.

pesterhazy14:01:59

how do you keep state around without defonce?

potetm14:01:28

I allow you to dictact a single var that will not be unloaded.

pesterhazy14:01:56

hmm. that actually seems inferior to defonce

potetm14:01:16

At the end of the day, you either unload the namespace or you don't. There's nothing in clojurescript to indicate a var is defonced or not.

potetm14:01:55

For comparison, tools.namespace also does not respect defonce.

potetm14:01:25

I'd agree that defonce is easier. It's definitely less work for the user. But the tradeoff is var unloading.

potetm14:01:51

In terms of being build-tool agnostic, I don't think that's a feasible goal for Figwheel. It's tied to Leiningen in a significant way. But @bhauman would obviously know more about that.

pesterhazy14:01:29

Does anyone know what's the entry point for react-virtualized (https://github.com/cljsjs/packages/tree/master/react-virtualized) in cljsjs?

pesterhazy14:01:39

window.ReactVirtualized does not exist

martinklepsch14:01:34

@pesterhazy is the file loaded for sure?

pesterhazy14:01:39

sicher ist nur der tod... but I added [cljsjs.react-virtualized] to the requires...

martinklepsch14:01:16

@pesterhazy in :none you should see it getting loaded in the “Sources” panel of your devtools

pesterhazy14:01:24

ahh cool didn't know that

pesterhazy14:01:30

is there, yes

pesterhazy14:01:08

!function(root, factory) {
    "object" == typeof exports && "object" == typeof module ? module.exports = factory(require("React"), require("React.addons.shallowCompare"), require("ReactDOM")) : "function" == typeof define && define.amd ? define([ "React", "React.addons.shallowCompare", "ReactDOM" ], factory) : "object" == typeof exports ? exports.ReactVirtualized = factory(require("React"), require("React.addons.shallowCompare"), require("ReactDOM")) : root.ReactVirtualized = factory(root.React, root["React.addons.shallowCompare"], root.ReactDOM);
}(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_10__) {

pesterhazy14:01:24

that's the head of the file

martinklepsch14:01:33

Now we need someone who understands javascript exports 😄

pesterhazy15:01:51

Uncaught TypeError: Cannot read property 'shallowCompare' of undefined <-- I think that's the issue

kasuko18:01:57

Is it possible to use Clojurescript to build a Javascript module that can be used with CommonJS?

kasuko18:01:39

Googling informs me there is lots of ways to use a CommonJS module with Clojurescript, but it’s hard to sift through to find the reverse direction?

emccue18:01:50

Only example I can think of is Mori, I would take a look at that as a general guide

emccue18:01:13

Remember that ClojureScript will pass out immutable data structures unless you explicitly convert (with #js or similar), which may or may not be desirable depending on what you are writing

edwthomas19:01:46

Is there a best practice for referencing minified versions of CSS files using Lein in a ClojureScript app? I am aware of lein-asset-minifier and it works great but what if I have multiple CSS files that I want to combine into a single minified one? In that case, I will continue to reference the individual CSS files while developing but reference the minified/combined version in my Production build. In the Javascript world I'm assuming you would use something like Gulp for this. Is there a standard way of handling this kind of a requirement via lein?

captainlexington19:01:00

First: is the file actually there?

ujjwalt19:01:58

@captainlexington Sorry it was an embarrassing mistake which I just figured out. The asset path was wrong.

shoxter20:01:47

Anyone have any idea how to solve this error on re-natal init ProjectName: Command failed: node -e "require('react-native/local-cli/cli').init('.', 'ProjectName')"

bhauman22:01:03

@potetm figwheel not tied to leiningen in any way

potetm23:01:32

@bhauman My apologies. I thought for some reason, you had to configure it with leiningen. Obviously not the case.

bhauman23:01:09

@potetm it also doesn't require cljsbuild at all

bhauman23:01:46

@potetm I'd appreciate it if you update your repo README to reflect that

bhauman23:01:39

Other than that I like what you are doing with tire iron and I'm looking forward to reading it 🙂

potetm23:01:23

I did already I think. Please tell me if it's not showing. @bhauman Thank you for correcting me. :)

potetm23:01:58

And thank you. I'm excited to hear any feedback you have.