devcards

Devcards aims to provide a visual REPL experience for ClojureScript https://github.com/bhauman/devcards
anmonteiro 2016-07-21T20:55:45.000009Z

@bhauman: what’s the purpose of the html-env? function in devcards?

anmonteiro 2016-07-21T20:56:19.000010Z

I can see you e.g. define some React lifecycle functions conditionally based on that

bhauman 2016-07-21T20:57:20.000011Z

for server side rendering

bhauman 2016-07-21T20:57:32.000012Z

its really not used and super brittle

anmonteiro 2016-07-21T20:57:58.000013Z

@bhauman: Right, I suspected that. but there are things like js/document.getElementById that are used throughout the code

bhauman 2016-07-21T20:58:04.000014Z

but basically I got the code to run in node for blog post rendering etc

bhauman 2016-07-21T20:58:33.000015Z

yeah but server side rendering doesn't use those code paths

anmonteiro 2016-07-21T20:58:57.000016Z

@bhauman: I wanna make the devcards-om-next stuff compatible with that too. could you point me to the code paths that it uses?

bhauman 2016-07-21T20:59:26.000017Z

I really don't think its worth the effort

bhauman 2016-07-21T20:59:48.000018Z

I haven't used that code since I first wrote it and it may not work anymore

bhauman 2016-07-21T20:59:56.000019Z

that was quite a while ago now

anmonteiro 2016-07-21T21:01:05.000020Z

gotcha

bhauman 2016-07-21T21:01:19.000021Z

If I were you I would see if I can render a devcard page in the first place

bhauman 2016-07-21T21:01:31.000022Z

in node that is

bhauman 2016-07-21T21:01:43.000023Z

all the code for this is at the bottom of core.cljs

anmonteiro 2016-07-21T21:02:35.000024Z

@bhauman: thanks, render-namespace-to-string seems to be one of the things I’m looking for

bhauman 2016-07-21T21:02:42.000025Z

render-namespace-to-string

bhauman 2016-07-21T21:02:46.000026Z

yep

bhauman 2016-07-21T21:03:17.000027Z

yeah if it renders to string bully for you ...

anmonteiro 2016-07-21T21:03:21.000028Z

@bhauman: this should work, I supose: (render-namespace-to-string *ns*)

bhauman 2016-07-21T21:04:37.000029Z

you also have to call load-data-from-channel

bhauman 2016-07-21T21:05:13.000030Z

@anmonteiro: before you make any render calls

anmonteiro 2016-07-21T21:05:34.000031Z

makes sense, yeah

anmonteiro 2016-07-21T21:05:39.000032Z

let me try that

bhauman 2016-07-21T21:05:59.000033Z

thats if things start up in node at all 🙂

bhauman 2016-07-21T21:06:30.000034Z

and I would start by passing an explicit ns

bhauman 2016-07-21T21:08:11.000035Z

and you also have to differentiate between the code that is just the card code and the code that is in the card... because the card may render but the card content may not. So starting with a bare hello world project may make more sense

anmonteiro 2016-07-21T21:11:25.000036Z

@bhauman: hrm, no errors, but render-namespace-to-string returns nil

anmonteiro 2016-07-21T21:12:09.000037Z

my mistake

bhauman 2016-07-21T21:12:09.000038Z

call get-cards-for-ns directly

anmonteiro 2016-07-21T21:12:11.000039Z

trying again

anmonteiro 2016-07-21T21:12:21.000040Z

wrong namespace 🙂

anmonteiro 2016-07-21T21:16:32.000042Z

@bhauman: get-cards-for-ns also returning nil

anmonteiro 2016-07-21T21:16:44.000043Z

correct ns now. I clearly must be doing something wrong

bhauman 2016-07-21T21:16:56.000044Z

and you called load-data ...

anmonteiro 2016-07-21T21:17:05.000045Z

yea

bhauman 2016-07-21T21:17:21.000046Z

oh you must make sure that you have devcards true in the :compiler

bhauman 2016-07-21T21:17:35.000047Z

otherwise they are compiled out of the build

anmonteiro 2016-07-21T21:17:44.000048Z

oh wow, now I then that comes to bite me again

bhauman 2016-07-21T21:18:14.000049Z

yeah I really want to make it opt-out instead of opt-in

bhauman 2016-07-21T21:18:21.000050Z

but that's a big change

bhauman 2016-07-21T21:18:30.000051Z

literally the opposite

anmonteiro 2016-07-21T21:19:53.000052Z

@bhauman: still no dice

anmonteiro 2016-07-21T21:20:12.000053Z

@devcards.system/app-state returns the initial state without any cards

bhauman 2016-07-21T21:20:24.000054Z

and you are calling load .... ?

anmonteiro 2016-07-21T21:20:46.000055Z

yeah

bhauman 2016-07-21T21:21:25.000056Z

I would make sure that the cards are in the build and clean and rebuild etc

anmonteiro 2016-07-21T21:22:12.000057Z

there are definitely calls to devcards.core.register_card in the compiled JS

bhauman 2016-07-21T21:25:58.000059Z

then make sure that those files are getting loaded

anmonteiro 2016-07-21T21:36:17.000060Z

@bhauman: so it needs to block in load-data-from-channel! somehow

anmonteiro 2016-07-21T21:36:37.000061Z

it’s only getting the register_card calls after I call render-namespace-to-string

anmonteiro 2016-07-21T21:55:52.000062Z

@bhauman: so a few problems I had to get through: 1. load-data-from-channel! needed to be called like this: (go (<! (dc/load-data-from-channel!))) 2. my NS had - which were munged so I needed to pass the munged symbol to render-namespace-to-string 3. now getting an error with React.renderToString because it moved to ReactDOMServer.renderToString in later versions of React

anmonteiro 2016-07-21T21:55:52.000063Z

¯\(ツ)

anmonteiro 2016-07-21T22:00:42.000065Z

using my own version of render-namespace-to-string works (just replaced React.renderToString with ReactDOMServer.renderToString)

anmonteiro 2016-07-21T22:00:56.000066Z

so kudos to you!

bhauman 2016-07-21T22:05:57.000067Z

I'll take a PR for sure, perhaps some doc strings?

bhauman 2016-07-21T22:06:14.000068Z

I'm really glad you made it through ...

anmonteiro 2016-07-21T22:06:51.000069Z

@bhauman: I’ll put something together in the next few days

anmonteiro 2016-07-21T22:07:18.000070Z

maybe also convert from demunged ns symbols to the actual (munged) keyword that devcards uses internally

bhauman 2016-07-21T22:07:22.000071Z

Only if you think it's valuable