Fork me on GitHub
#hoplon
<
2017-02-27
>
jamieorc02:02:01

interested in implementing server side of Castra in Ruby. Am I nuts? Is it possible? What do you guys think?

micha02:02:57

sure, why not?

micha02:02:05

it was originally implemented in php

onetom03:02:02

i was looking a bit deeper into javelin over the weekend, because i was trying to make the cell graph reloadable. @micha i remember you mentioned something about the lack of weak references and garbage collecting cells. do i understand well, there is no way to reset the formula cell graph by just using boot-reload, while still preserving the stem cell state?

mudphone09:02:09

Is there a way to require a .hl file from the boot repl so I can play with functions in the repl?

mudphone11:02:38

Sorry if that’s an obvious question, I’m pretty new to boot and hoplon and have been looking through the docs. I’ve tried a few things in the boot repl and haven’t found it via some obvious attempts.

dm311:02:38

hl files are processed by the boot-hoplon plugin which converts them into .cljs files

dm311:02:46

which are then compiled by the Clojurescript compiler

dm311:02:24

you can start a cljs repl which, when connected to some javascript runtime, will allow interacting with the state

mudphone11:02:56

i see, i’m trying to connect my JVM to something running in the browser 🙂

dm311:02:06

yeah, you need a Clojurescript repl

mudphone11:02:16

ah, of course, ha

mudphone11:02:44

ooh, thank you

mudphone12:02:38

so, once I’ve got the browser repl hooked up (and it seems to be working already), can I change ns into my .hl ns?

mudphone12:02:44

(via in-ns)

mudphone12:02:50

hmm, I just did a clojure.tools.namespace/find-namespaces-on-classpath and didn’t find my namespaces from the cljs-repl

dm312:02:37

I don’t think it works that way

dm312:02:57

tools.namespace only works for Clojure namespaces

dm312:02:13

I’m not sure you can in-ns in Clojurescript, however I’ve never tried

mudphone13:02:04

can you run the fns that you’ve defn’d in a .hl file?

mudphone13:02:42

oh, so do you have to require a ns?

dm313:02:11

did you try (require ‘your.ns)?

mudphone13:02:01

I have, but get a file not found

dm313:02:12

due to the way cljs works all your namespaces accessible from the main script will already have been loaded

dm313:02:22

by the time you’re connected to the repl

dm313:02:57

I’m pretty sure you can’t load cljs namespaces dynamically unless you eval them

mudphone13:02:45

for example, what would the ns be for a file with (page “chapter1-1.html”) at the top

mudphone13:02:17

located in src/chapter1_1.cljs.hl

dm313:02:40

I don’t really know 🙂 you’d have to look at the boot fileset or with the devtools in the browser

dm313:02:47

I don’t use cljs repl

mudphone13:02:48

ha, okay, thanks

mudphone13:02:17

well @dm3 thanks for your help, I feel like I’m closer. I better get some sleep now though.

micha13:02:03

@mudphone the cljs namespace name is generated

micha13:02:35

you can see it in the js console if you put something like (print "hi there") in your .hl file

micha13:02:55

the devtools should show the namespace, file, and line number in the console

micha13:02:14

line numbers should be preserved

micha13:02:30

you should be able to require that namespace

micha13:02:34

in the cljs repl

mudphone13:02:03

When I add (print “hi there”), and look in the browser console, I see:

mudphone13:02:24

hi there  …  repl.cljs:47

micha13:02:33

oh interesting

micha13:02:38

do you get a stack trace?

dm313:02:40

@micha are you sure the require will do anything? The wiki above indicates you need to use load-namespace/`load-file`

micha13:02:03

well you can always do (print (.-stack (js/Error. "hello")))

micha13:02:10

in your .hl file

mudphone13:02:18

oh, I found this in the browser: hoplon.app_pages._chapter1_1_DOT_html

micha13:02:32

there we go, that's it

mudphone13:02:36

in the goog.require

mudphone13:02:00

Thank you. I clearly have a lot to learn.

micha13:02:22

it does that because you could have a html file named for instance 1.html

micha13:02:37

which isn't a valid symbol

micha13:02:03

symbols can't start with a number etc

micha13:02:21

also you don't want generated namespaces to collide with other ones

micha13:02:40

so it namespaces them in the hoplon.app-pages package

micha13:02:56

and prepends a _ to your page name

micha13:02:59

and munges it

micha13:02:33

i am not sure anymore about the procedure for loading a namespace in the cljs repl

mudphone14:02:05

do people not do this often? i’m new to this so, maybe it’s not a normal thing to do?

micha14:02:34

i use the live reload instead of a cljs repl usually

micha14:02:53

i find it's pretty simple to just do like

micha14:02:20

(cell= (pr some-cell-i-want-to debug))

micha14:02:31

in a file and when i save it i see the output in the js console

mudphone14:02:59

ah, okay, I think I remember seeing that in one of the docs

mudphone14:02:29

i suppose one other option is using .cljc files and using the normal repl?

micha14:02:42

you still need a cljs repl

micha14:02:51

separate from the clj one

micha14:02:02

the clojure compiler will ignore cljs parts

mudphone14:02:08

oh, I meant to just test a normal fn, not the hoplon bits

mudphone14:02:22

i guess that wouldn’t be real useful

dm314:02:31

some people swear by the cljs repl

dm314:02:49

I guess it works fine once you develop a workflow

dm314:02:00

there’s also Dirac and cljs-devtools

mudphone14:02:59

Thanks for the tips and assistance. Much appreciated.

candera14:02:42

@mudphone I think there are real advantages to keeping as much of your app as is reasonable in .cljc files. One is the JVM REPL. As cool and handy nas the CLJS REPL is, it still lacks a number of things that the JVM REPL has. E.g. vars, but also tooling.

micha14:02:49

@candera for jvm repl is .cljc better than .clj files?

candera14:02:21

Not better per se.

candera14:02:41

If I’m doing a bunch of stuff that’s clearly in JVM-land, then I go with .clj rather than a .cljc with a bunch of reader conditionals.

candera14:02:45

All sort of depends.

candera14:02:18

But often there’s a bunch of purely algorithmic stuff, and I find that putting that in a CLJC doesn’t cost me anything and lets me use it in my CLJS app but still play with it in my JVM REPL.

micha14:02:40

that makes sense

mudphone18:02:52

@candera thank you, for some reason, now that you've said that, I'm wondering if I heard you say that on a podcast :)

candera18:02:15

Maybe - I don’t listen to anything I say.

mudphone18:02:39

Ha, well, I really enjoyed your show (still do). I think was my favorite, you certainly have a knack.

mudphone18:02:00

(Best or good enough :)

jamieorc22:02:30

@micha Thanks, I just needed a reality check of whether I was being insane thinking of it. I would love to be able to start converting to hoplon from within a Ruby app, but I would rather use the RPC style than other.

candera22:02:49

@mudphone Thanks for the kind words. Glad you enjoy the show. That wiki page seems like a decent place to start.

candera22:02:53

The process is pretty straightforward, though. If you’re in the JVM, and try to load namespace foo.bar, the compiler will first look for foo/bar.clj, then foo/bar.cljc. If you’re in CLJS land, it will first look for foo/bar.cljs, then for foo/bar.cljc.

mudphone22:02:56

Yes! I remember seeing that load order in the errors I was generating while blindly searching for my namespace in the repl.

candera22:02:57

It can make sense to have both a foo/bar.clj and a foo/bar.cljs. I do this, for example, to provide alternate versions of a set of functions for reading files depending on whether I’m running in Node or the JVM. But I can’t think of a reason to have a .cljc and either of the other two. And of course you can use reader conditionals in your .cljc to get different code depending on which context you’re in. That’s handy from time to time, but I find myself staying away from writing too much code like that.