Fork me on GitHub
#clojurescript
<
2017-07-22
>
isaac03:07:18

Var now is reified in cljs at runtime

isaac03:07:40

There has deref supports on Var, but not var-get?

scknkkrer10:07:51

Guys, I really don’t understand some basics of clojurescript. I added an npm package to my project, I require that from an js file and then I can use it. But, how can I require this library from clojurescript ?

mrchance10:07:11

It's pretty easy now 🙂

scknkkrer11:07:28

Not like that. There is a function call in my template (def ReactNative (js/require "react-native"))

scknkkrer11:07:07

This compiles to ios.js file. But I want to require external library.

scknkkrer11:07:12

It doesn’t.

scknkkrer11:07:31

(def ReactNative (js/require "native-base"))

scknkkrer11:07:51

sorry It’s NativeBase.

mrchance11:07:50

Also this: https://clojurescript.org/reference/compiler-options#foreign-libs (which is linked in the blog entry as well)

octahedrion15:07:10

is there no workaround for the lack of

map-entry?
in CLJS ?

noisesmith15:07:21

+cljs.user=> (type (first {:a 0}))
cljs.core/PersistentVector
that's tricky

noisesmith15:07:31

it's a vector and has exactly two items?

noisesmith15:07:17

yeah, without a separate type to look for you are kind of stuck

noisesmith15:07:53

this surprises me...

+cljs.user=> (def v [:a 0])
#'cljs.user/v
+cljs.user=> (identical? v (first (conj {} v)))
false

octahedrion15:07:30

(identical? v [:a 0])

jeremys15:07:56

hey @noisesmith take a look at the type of (first (conj {} v)) I am not sure in cljs but in clojure it would probably a map entry, not a vector

octahedrion15:07:09

yeh that's the point

noisesmith15:07:18

@octo221 my surpise is that it doesn't just use the vector, since conj will be putting a vector into the hash-map

noisesmith15:07:43

@jeremys the point of this convo is that elements in hash maps in cljs are vectors

octahedrion15:07:02

does the same for (into {})

noisesmith15:07:10

+cljs.user=> (type (first (conj {} v)))
cljs.core/PersistentVector

noisesmith15:07:21

@octo221 into uses conj (or conj!) yeah

jeremys15:07:30

ok so no map entry type

noisesmith15:07:39

right, now you've caught up

jeremys15:07:10

yep but still I am not surprised identical doesn’t works there

noisesmith15:07:29

my surprise is because if it puts a vector in anyway, it could just use the vector

noisesmith15:07:42

probably its in order to keep the code diffs from clj as small as possible

octahedrion15:07:50

it's nice to know the provenance of data

jeremys15:07:52

when you ‘add’ the vector to the map, the internals take the values in your map and store them

noisesmith15:07:18

right but it doesn't have to - and clojure's usually smart about reusing persistent data when it can

jeremys15:07:38

when you retrieve them the map has to constuct a new vector to give you a key-value pair

octahedrion15:07:46

yes like how subvec reuses the parent vec

noisesmith15:07:50

retrieval does not create a new entry

noisesmith15:07:01

a hash map contains the entries

noisesmith15:07:19

you can go into your js debugger and find them if you inspect it

jeremys15:07:49

no the hash map contains a tree like datastructure use for efficient retreiving of value from keys

jeremys15:07:25

that’s weird

noisesmith15:07:42

oh wait - it doesn't have the map entries in the structure

noisesmith15:07:03

so that explains why the vector you get back isn't identical

noisesmith15:07:46

it's a an array below a certain size, then a tree of 32 element arrays, OK

jeremys15:07:58

yep I think the contract is that = would work but not identical?

noisesmith15:07:26

I was just confused about the inner structure

jeremys15:07:34

and by the way there is a map entry type

noisesmith15:07:58

then why don't we see it?

jeremys15:07:59

it is weird it gave you vector

jeremys15:07:07

that I don’t know mate

noisesmith15:07:08

that's not a type it's an interface - which is extended to collections

noisesmith15:07:11

(later in the file)

noisesmith15:07:19

so there's no concrete map entry type

noisesmith15:07:07

n/m that's the line you linked to, now I'm catching up

jeremys15:07:16

lol no problem

jeremys15:07:26

but you can take a look at this

noisesmith15:07:34

oh! MapEntry type was added in 1.9.542

noisesmith15:07:04

so I bet in that version or newer you can actually test for entries - this repl is a month or two old, that's what's going on

jeremys15:07:06

shoot I lost the line give me a sec

jeremys15:07:43

I lost the line but I saw an implementation of ISeq returning a set of vectors somewhere, which might be why we get vectors instead of map entries

jeremys15:07:06

a *seq of vectors...

noisesmith15:07:42

my cljs is older, it doesn't have that type yet

noisesmith15:07:47

I need to update my repl

jeremys16:07:27

I trying the latest atm to try the new code splitting and I will try requiring from node_modules

jeremys16:07:33

cool stuff

jeremys16:07:45

just used code splitting to compile my devcards in the same build that compiles my app main, I should be able to hot reaload them at the same time. pretty cool

profgra20:07:52

Hi all, I have a reframe project in which I include an npm module. It compiles OK with :optimizations :simple but not with :advanced. Should I file a bug? is there a list of such known problems? More details here: https://stackoverflow.com/questions/45201315/a-is-undefined-when-compiling-a-cljs-prj-with-an-npm-module-under-prod-profil

jeremys22:07:25

Hey guys, has somone tried the new :npm-deps stuff? I am trying it to use mui with the muicss npm package but can’t find how to properly require things.