lein-figwheel

Karol Wójcik 2018-08-12T16:34:40.000030Z

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

Karol Wójcik 2018-08-12T16:34:52.000068Z

I will check what is comming to the read fn

Karol Wójcik 2018-08-12T16:49:26.000042Z

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

bhauman 2018-08-12T16:49:47.000074Z

that's not on the path

bhauman 2018-08-12T16:50:01.000078Z

the link I gave you previously is

Karol Wójcik 2018-08-12T16:50:09.000058Z

It's a problem with my understanding then

Karol Wójcik 2018-08-12T16:50:21.000025Z

I will try to investigate it further then

bhauman 2018-08-12T16:50:52.000034Z

this is where it comes in https://github.com/bhauman/figwheel-repl/blob/master/src/figwheel/repl.cljc#L693

bhauman 2018-08-12T16:51:22.000035Z

all messages from the client flow through there

bhauman 2018-08-12T16:51:46.000027Z

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

bhauman 2018-08-12T16:52:10.000052Z

figwheel repl has all the communication code in it

bhauman 2018-08-12T16:52:23.000096Z

both the client side and server side

bhauman 2018-08-12T16:53:35.000043Z

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

bhauman 2018-08-12T16:53:43.000055Z

I hope I'm giving you helpful info

Karol Wójcik 2018-08-12T16:53:48.000084Z

Yes you do

Karol Wójcik 2018-08-12T16:54:25.000057Z

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

Karol Wójcik 2018-08-12T16:54:36.000004Z

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

Karol Wójcik 2018-08-12T16:56:44.000031Z

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

Karol Wójcik 2018-08-12T16:57:30.000038Z

Ok may I ask some questions please?

bhauman 2018-08-12T16:57:41.000067Z

sure

Karol Wójcik 2018-08-12T16:59:03.000059Z

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ójcik 2018-08-12T17:00:03.000114Z

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

bhauman 2018-08-12T17:00:31.000011Z

the client is the host javascript environment

bhauman 2018-08-12T17:00:52.000010Z

the server is the Clojure jvm environment

bhauman 2018-08-12T17:01:09.000107Z

lein-figwheel does not depend on figwheel-repl

bhauman 2018-08-12T17:01:15.000029Z

figwheel-main does

bhauman 2018-08-12T17:01:35.000056Z

figwheel-main only uses the REPL channel for communication

Karol Wójcik 2018-08-12T17:02:29.000032Z

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.

bhauman 2018-08-12T17:02:59.000015Z

yes,

Karol Wójcik 2018-08-12T17:03:16.000014Z

Maybe I will just compare the two forms

bhauman 2018-08-12T17:03:32.000068Z

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

bhauman 2018-08-12T17:03:42.000086Z

at the root

bhauman 2018-08-12T17:03:59.000034Z

oh wait,

bhauman 2018-08-12T17:04:20.000061Z

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

bhauman 2018-08-12T17:04:28.000049Z

which I bet may be the case

Karol Wójcik 2018-08-12T17:04:37.000010Z

XD

Karol Wójcik 2018-08-12T17:04:44.000050Z

I really like you 😛

Karol Wójcik 2018-08-12T17:05:00.000009Z

This is the second time we have a conversation

Karol Wójcik 2018-08-12T17:05:32.000013Z

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

Karol Wójcik 2018-08-12T17:05:37.000033Z

but it's good

Karol Wójcik 2018-08-12T17:06:36.000072Z

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

bhauman 2018-08-12T17:07:54.000055Z

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

👍 1
Karol Wójcik 2018-08-12T17:08:59.000067Z

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.

bhauman 2018-08-12T17:09:23.000066Z

definitely not just slicing the string

bhauman 2018-08-12T17:09:57.000005Z

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

bhauman 2018-08-12T17:10:20.000044Z

you should experiment with that in the REPL

bhauman 2018-08-12T17:10:27.000026Z

not in figwheel

bhauman 2018-08-12T17:10:38.000030Z

until you get a result that works for you

bhauman 2018-08-12T17:10:51.000020Z

work in the REPL because it will be quicker

bhauman 2018-08-12T17:11:04.000024Z

than restarting everything and setting it all up

Karol Wójcik 2018-08-12T17:12:40.000006Z

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

bhauman 2018-08-12T17:14:33.000021Z

sounds good to me

bhauman 2018-08-12T17:18:30.000007Z

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

bhauman 2018-08-12T17:18:36.000081Z

which is too bad

Karol Wójcik 2018-08-12T17:18:44.000003Z

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?

bhauman 2018-08-12T17:21:10.000071Z

they both receive raw strings that represent map messages

bhauman 2018-08-12T17:21:37.000039Z

can't be parsed on the client side

bhauman 2018-08-12T17:22:29.000075Z

its the same in both cases

Karol Wójcik 2018-08-12T17:23:04.000058Z

;O

Karol Wójcik 2018-08-12T17:24:19.000056Z

It must be different somewhere

Karol Wójcik 2018-08-12T17:26:52.000036Z

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

Karol Wójcik 2018-08-12T17:27:02.000085Z

Thank you @bhauman

bhauman 2018-08-12T17:27:29.000072Z

it may not be

bhauman 2018-08-12T17:27:46.000024Z

different it may be that the error handling is different

bhauman 2018-08-12T17:29:55.000003Z

OK well I fixed it with this

bhauman 2018-08-12T17:30:24.000077Z

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

bhauman 2018-08-12T17:31:04.000007Z

the *read-eval* is required for safety

Karol Wójcik 2018-08-12T17:31:22.000075Z

;(((((((

Karol Wójcik 2018-08-12T17:31:30.000002Z

Very sad I'am 😄

bhauman 2018-08-12T17:32:03.000092Z

it's not a straight forward problem

bhauman 2018-08-12T17:32:24.000065Z

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

Karol Wójcik 2018-08-12T17:32:25.000013Z

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

bhauman 2018-08-12T17:32:30.000011Z

sure

bhauman 2018-08-12T17:34:18.000032Z

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

bhauman 2018-08-12T17:38:14.000012Z

oh my god I know what the problem is

bhauman 2018-08-12T17:38:30.000020Z

geeeeez

bhauman 2018-08-12T17:38:47.000074Z

oh yeah this is rich

Karol Wójcik 2018-08-12T17:39:34.000080Z

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.

bhauman 2018-08-12T17:40:31.000002Z

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

bhauman 2018-08-12T17:40:45.000023Z

and I just return the data

bhauman 2018-08-12T17:40:58.000037Z

basically ignoring the tag altogether

Karol Wójcik 2018-08-12T17:41:20.000049Z

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

bhauman 2018-08-12T17:41:20.000071Z

as you said

Karol Wójcik 2018-08-12T17:42:04.000033Z

Ok so what was the difference in figwheel.main?

Karol Wójcik 2018-08-12T17:42:12.000011Z

What was the problem?

bhauman 2018-08-12T17:42:32.000020Z

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

Karol Wójcik 2018-08-12T17:43:02.000041Z

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

Karol Wójcik 2018-08-12T17:43:49.000070Z

This is what you're talking about?

bhauman 2018-08-12T17:43:53.000068Z

yep

Karol Wójcik 2018-08-12T17:43:56.000040Z

😄

bhauman 2018-08-12T17:44:19.000072Z

and it returns nil

bhauman 2018-08-12T17:44:30.000048Z

which is works just fine

Karol Wójcik 2018-08-12T17:44:47.000050Z

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

Karol Wójcik 2018-08-12T17:45:00.000031Z

To ensure consistency between two

bhauman 2018-08-12T17:45:30.000021Z

they are both so different in this regard

bhauman 2018-08-12T17:46:04.000031Z

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

bhauman 2018-08-12T17:46:12.000016Z

as its the best solution

Karol Wójcik 2018-08-12T17:46:19.000009Z

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

bhauman 2018-08-12T17:46:43.000034Z

if you really want to go down the rabbit hole

Karol Wójcik 2018-08-12T17:46:54.000050Z

Yes I want 😛

bhauman 2018-08-12T17:46:55.000007Z

this is only a problem with ns forms

bhauman 2018-08-12T17:47:31.000035Z

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

bhauman 2018-08-12T17:47:40.000030Z

in lein-figwheel

bhauman 2018-08-12T17:47:56.000081Z

it will effortlessly print out "#js {}"

bhauman 2018-08-12T17:48:24.000083Z

but ns forms are handled differently

bhauman 2018-08-12T17:48:36.000032Z

by the ClojureScript REPL

Karol Wójcik 2018-08-12T17:51:11.000030Z

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

bhauman 2018-08-12T17:51:13.000078Z

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

bhauman 2018-08-12T17:51:59.000046Z

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

bhauman 2018-08-12T17:52:38.000048Z

thanks for taking the ride 🙂

Karol Wójcik 2018-08-12T18:07:09.000006Z

I'm back

Karol Wójcik 2018-08-12T18:07:13.000042Z

Ok I see 😛

Karol Wójcik 2018-08-12T18:07:28.000064Z

That was pleasure for me to take the lesson from you

bhauman 2018-08-12T18:08:11.000031Z

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

bhauman 2018-08-12T18:08:27.000060Z

it was fun for me as well

Karol Wójcik 2018-08-12T18:10:44.000058Z

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.

bhauman 2018-08-12T18:12:14.000072Z

I'd ask about that in #cider

Karol Wójcik 2018-08-12T18:15:58.000030Z

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.

👍 1