Fork me on GitHub
#lein-figwheel
<
2018-08-12
>
Karol Wójcik16:08:40

@bhauman as I can see the figwheel-main doesn't have that issue

Karol Wójcik16:08:52

I will check what is comming to the read fn

Karol Wójcik16:08:26

@bhauman I think that this is because in figwheel main you are using cljs data readers in figwheel-main/src/figwheel/main/evalback.cljc

bhauman16:08:47

that's not on the path

bhauman16:08:01

the link I gave you previously is

Karol Wójcik16:08:09

It's a problem with my understanding then

Karol Wójcik16:08:21

I will try to investigate it further then

bhauman16:08:22

all messages from the client flow through there

bhauman16:08:46

and its in figwheel-repl which is maybe why you didn't see it

bhauman16:08:10

figwheel repl has all the communication code in it

bhauman16:08:23

both the client side and server side

bhauman16:08:35

@kwcharllie379 thanks for taking the time to try and understand this

bhauman16:08:43

I hope I'm giving you helpful info

Karol Wójcik16:08:25

But the problem is that I'm just the noob. Trying to wrap my head around all that code.

Karol Wójcik16:08:36

I think I will do this and I really appreciate your help

Karol Wójcik16:08:44

Trying to search through the regular figwheel to see where the figwheel-repl is

Karol Wójcik16:08:30

Ok may I ask some questions please?

Karol Wójcik16:08:03

OK so the client is emacs or browser which sends the form to the figwheel-repl which responds with the result of the evaluation back to the client. Do I understand that correctly?

Karol Wójcik17:08:03

As I can see the regular figwheel does not depend on figwheel-repl or I cannot see that ;( Therefore communication is slithly different there

bhauman17:08:31

the client is the host javascript environment

bhauman17:08:52

the server is the Clojure jvm environment

bhauman17:08:09

lein-figwheel does not depend on figwheel-repl

bhauman17:08:15

figwheel-main does

bhauman17:08:35

figwheel-main only uses the REPL channel for communication

Karol Wójcik17:08:29

Yes but as I said the problem only occurs in regular figwheel. Figwheel-main can get some different form then regular figwheel. Therefore the figwheel-main is able to parse it.

Karol Wójcik17:08:16

Maybe I will just compare the two forms

bhauman17:08:32

but if the problem is on the client side where the data is sent then maybe we can fix it most easiliy there?

bhauman17:08:42

at the root

bhauman17:08:20

OR maybe there is just better error handling in figwheel-main

bhauman17:08:28

which I bet may be the case

Karol Wójcik17:08:44

I really like you 😛

Karol Wójcik17:08:00

This is the second time we have a conversation

Karol Wójcik17:08:32

and in this one I also felt like I was a little kid 😛

Karol Wójcik17:08:36

I especially like that you help me understand all the magic in Clj world.

bhauman17:08:54

you'd be surprised how straight forward it is once you take the dive, but its really hard/impossible to learning everything at once especially from the CLJS side

👍 4
Karol Wójcik17:08:59

I am thinking whether we should just fix the problem by slicing the string or we should take care to provide the same user experience as in figwheel-main.

bhauman17:08:23

definitely not just slicing the string

bhauman17:08:57

(binding [*default-data-reader-fn* identity]
            (edn/read-string data))

bhauman17:08:20

you should experiment with that in the REPL

bhauman17:08:27

not in figwheel

bhauman17:08:38

until you get a result that works for you

bhauman17:08:51

work in the REPL because it will be quicker

bhauman17:08:04

than restarting everything and setting it all up

Karol Wójcik17:08:40

Ok so the strategy is to: 1. Rebind the default-data-reader-fn to handle #js parts. 2. Then use it in the read-msg. 3. Ask you whether it's looking good 😛 4. Do PR and merge

bhauman17:08:33

sounds good to me

bhauman17:08:30

ok looks like you have to use read-string not edn/read-string

bhauman17:08:36

which is too bad

Karol Wójcik17:08:44

Last question: As I can see https://github.com/bhauman/figwheel-repl/blob/master/src/figwheel/repl.cljc#L690 receives the message from the client (Node.js/Javascript/Cljs ecosystem). It could be already parsed by the client to regular map. But in regular figwheel I just receive the form which is not so easy to parse because I do not have the access to data-reader-fn from cljs?

bhauman17:08:10

they both receive raw strings that represent map messages

bhauman17:08:37

can't be parsed on the client side

bhauman17:08:29

its the same in both cases

Karol Wójcik17:08:19

It must be different somewhere

Karol Wójcik17:08:52

Ok I think I will just focus on solving that issue.

bhauman17:08:29

it may not be

bhauman17:08:46

different it may be that the error handling is different

bhauman17:08:55

OK well I fixed it with this

bhauman17:08:24

(binding [*read-eval* false
                *default-data-reader-fn* (fn [tag res] res)]
            (read-string data))

bhauman17:08:04

the *read-eval* is required for safety

Karol Wójcik17:08:30

Very sad I'am 😄

bhauman17:08:03

it's not a straight forward problem

bhauman17:08:24

and I'd still like to know what's going on

Karol Wójcik17:08:25

May I please try to tell you how I understand that code?

bhauman17:08:18

and remember I'd still like to know what's different in figwheel.main

bhauman17:08:14

oh my god I know what the problem is

bhauman17:08:47

oh yeah this is rich

Karol Wójcik17:08:34

So while reading the msg you take the tagged literal and throw it away. So you just receiving the safety string which might be then evaluated to the map.

bhauman17:08:31

close, the (fn [tag res] ) recieves a tag and already parsed data as res

bhauman17:08:45

and I just return the data

bhauman17:08:58

basically ignoring the tag altogether

Karol Wójcik17:08:20

ok so you got the map (data) and the tag 😛 and you ignore the tag

bhauman17:08:20

as you said

Karol Wójcik17:08:04

Ok so what was the difference in figwheel.main?

Karol Wójcik17:08:12

What was the problem?

bhauman17:08:32

I think it has the same problem, but it handles the error better

Karol Wójcik17:08:02

Looking into the code I can see it's just pprints therefore the error does not look like an error.

Karol Wójcik17:08:49

This is what you're talking about?

bhauman17:08:19

and it returns nil

bhauman17:08:30

which is works just fine

Karol Wójcik17:08:47

Maybe this is what should be applied to the regular figwheel as well

Karol Wójcik17:08:00

To ensure consistency between two

bhauman17:08:30

they are both so different in this regard

bhauman17:08:04

but I'm going to add patch to figwheel.main as well

bhauman17:08:12

as its the best solution

Karol Wójcik17:08:19

PS: In future I will figure the solution by myself so the contribution will be count to me 😛

bhauman17:08:43

if you really want to go down the rabbit hole

Karol Wójcik17:08:54

Yes I want 😛

bhauman17:08:55

this is only a problem with ns forms

bhauman17:08:31

you can see this if you eval (do #js {}) in your editor buffer cider

bhauman17:08:40

in lein-figwheel

bhauman17:08:56

it will effortlessly print out "#js {}"

bhauman17:08:24

but ns forms are handled differently

bhauman17:08:36

by the ClojureScript REPL

Karol Wójcik17:08:11

Mein God. Does not understand that code but I will 😛 Need 10 minutes of rest

bhauman17:08:13

the clojurescript repl wraps all forms with pr-str except 'ns 'require 'require-macros etc

bhauman17:08:59

so its only in this case where an 'ns form returns javascript that this is a problem

bhauman17:08:38

thanks for taking the ride 🙂

Karol Wójcik18:08:28

That was pleasure for me to take the lesson from you

bhauman18:08:11

I'm still going to mess with it a bit more and try to use clojure.tools.reader.edn/read-string instead as its safer

bhauman18:08:27

it was fun for me as well

Karol Wójcik18:08:44

Last last question 🙂 Is it possible to somehow force the emacs to return to user.ns=> in figwheel-main after the code reloads? The problem is that the compilation succeeds but it does not return to user.ns=> and when I try to evaluate the (println "some-str") form then the result shows on the top of the repl while it should on the bottom.

bhauman18:08:14

I'd ask about that in #cider

Karol Wójcik18:08:58

Ok thanks 🙂 Of course I can switch to repl and just use enter but was looking for a moreprogrammatic way. Thank you one more time for the ride 😉 Have a nice day and see you around.

👍 4