Fork me on GitHub
#clojurescript
<
2019-02-16
>
tomaas00:02:10

hi, using the firebase lib from cljsjs (aset (js/firebase.auth) "languageCode" "fr") expression does work when compiled with :advanced option.

tomaas00:02:56

https://github.com/firebase/firebase-js-sdk/blob/master/packages/firebase/externs/firebase-auth-externs.js firebase.auth.Auth.prototype.languageCode; appears, which i suppose the firebase wrapper in cljsjs uses

tomaas00:02:29

why then this does work with :advanced compilation and how can i fix it?

Shantanu Kumar10:02:29

Hi. How would one write (cljs.test/is (thrown-with-msg? CLJS-class #"foo" (throw (ex-info "foo" {})))) - as in, what should take the place of CLJS-class?

dominicm10:02:42

js/Error I think is what you want?

Shantanu Kumar11:02:47

@dominicm Yes, that worked - thanks!

vlad_poh18:02:59

Is there a library that takes html and generates reagent compatible hiccup?

gklijs19:02:25

There several online ones like https://htmltohiccup.herokuapp.com/ I guess there should also be a library that does it.

👍 5
vlad_poh19:02:36

Great! Thanks!

zane19:02:06

Anyone know why these two expressions would print different results?

cljs.user=> (let [state (cljs.js/empty-state)]
       #_=>   (cljs.js/eval state '(def x 1) {:eval cljs.js/js-eval} prn)
       #_=>   (cljs.js/eval state 'x {:eval cljs.js/js-eval} prn))
{:value 1}
{:value nil}
nil
cljs.user=> (let [state (cljs.js/empty-state)]
       #_=>   (cljs.js/eval state '(def x 1) {:eval cljs.js/js-eval, :context :expr} prn)
       #_=>   (cljs.js/eval state 'x {:eval cljs.js/js-eval, :context :expr} prn))
{:value 1}
{:value 1}
nil

zane19:02:01

The docs for cljs.js/eval claim that :context :expr is the default: http://cljs.github.io/api/cljs.js/eval

zane19:02:27

I'm sure I'm missing something simple.

thheller19:02:09

@zane assuming you are running things exactly like that the first time cljs.user.x = 1 will be set in JS

thheller19:02:19

since you don't restart the runtime inbetween that value is still there the second time

zane20:02:18

@thheller The thing that is confusing me is why simply cljs.js/evaluating x right after (def x 1) prints nil if :context :expr is not set.

zane20:02:14

@thheller Additionally, I don't believe defining things via cljs.js/eval (self-hosted ClojureScript eval) ever affects the environment of the caller. Do you have a different understanding?

zane20:02:35

I'd test it but I'm away from my computer.

thheller20:02:32

@zane everything you eval is eval'd in your runtime (eg. the browser), nothing is isolated. empty-state only affects the CLJS analyzer state, not the state of the runtime itself.

zane20:02:02

@thheller Then what's happening in the first let?

zane20:02:35

I assume it's interpreting it as a statement and the docs are wrong?

thheller20:02:30

uhm yeah that maybe right. not actually sure if cljs.js/eval does some async stuff. if it does it may just be async not having eval'd yet.

zane20:02:12

Ah, yeah. Could be a race condition.

thheller20:02:11

it may just be the :context :expr thing alone since the code will just not emit anything to eval

zane20:02:45

@thheller Thanks for the help! Is there something I could read to understand what the analyzer state is/is for?

zane20:02:23

I don't have a good mental model of how self-hosting works at all.

thheller20:02:24

hehe me neither. always hurts my head thinking about it. analyzer data is used by cljs.analyzer for code generation stuff. It keeps all data about defn&co defined in your namespaces.

zane20:02:05

@thheller Got it. Does that apply to macros?

thheller20:02:07

not actually sure in self-hosted but I guess it will keep some infos about macros in there as well yes

john21:02:35

Yeah, eval* calls ana/empty-env which defaults to :statement

john21:02:29

Good catch @zane!

john21:02:00

Might be a good chance to contribute a fix, if haven't had a chance to yet

zane21:02:58

@john I've been looking for one!

john21:02:39

Nice! If you're interested, I'd check in with the devs over at #cljs-dev and get an opinion on whether it's a doc string error or a code error.

john21:02:28

If you want to try changing the default to :expr then you should probably make sure to run the self host tests to make sure everything still works.

5
john21:02:03

Another strategy would be to let ana/empty-env default still to :statement and check for lack of :context in eval*'s params and give it :expr if so. And test against that.

john22:02:02

But if it's a doc string thing, there looks to be a number of different fns that declare :expr as the default in their doc strings, so they may be wrong too.

john22:02:43

If nobody sees it this weekend, somebody should probably see it this week. Remember to sign the contributor agreement https://clojurescript.org/community/contributing if you want to end up sending in a patch.