Fork me on GitHub
#clojurescript
<
2019-12-30
>
didibus00:12:47

Ya, the whole thing involves proper trade offs. I think the idea of live view is to treat web UIs like online games do. But the truth is that all it is doing is starting from the other side, and in both situation where you want to end up is somewhere in the middle

didibus00:12:50

Most online game have quite a few tech in the client as well allowing the illusion of smoothness until sync happens

didibus00:12:36

But the truth of LiveView is that its just trying to build a Elixir only full stack. And since it can't compile to JS, they tried taking a full server side approach

jjttjj04:12:43

Slightly tangential, but I read recently in the first comment here https://news.ycombinator.com/item?id=21821327 that Bloomberg terminals do all rendering server side with spidermonkey and send the results back to the (non web) client

craftybones05:12:08

Should a Clojure backend send data as edn to a Clojurescript or JSONify it and then js->clj over it at the other end? If I do send it as edn, is it simply an edn/read-string operation on the frontend?

Alex Miller (Clojure team)05:12:59

Transit is designed for this purpose

Alex Miller (Clojure team)05:12:20

It’s faster and smaller than edn or json

craftybones09:12:20

A cursive question. Is there a quick way to get to the end of the line? cmd -> is mapped to move around to next form. Annoying as hell

Joni09:12:47

Home for start of line End for end of line?

p-himik09:12:38

@srijayanth What prevents you from unmapping the shortcut in the settings?

craftybones09:12:24

@U2FRKM4TW - that’s what I am ending up having to do, now I have to come up with other shortcuts for navigating through the forms. I am on a mac but without a mac keyboard

p-himik09:12:56

Seems like a good opportunity to pitch IdeaVim. :D

craftybones13:12:23

Function key and right arrow, not code 🙂

craftybones13:12:36

How do I start my own server using leiningen in a figwheel project? I am trying to use a lein exec. I have a script called server.clj. Pretty much like https://figwheel.org/docs/your_own_server.html but with leiningen instead of CLI

craftybones13:12:07

Classpath errors. Doesn’t find ring on the classpath

craftybones13:12:40

It finds ring, doesn’t find the jetty adapter. Upon reading, it looks like the ring jetty adapter is a separate dependency. Fixed.

craftybones14:12:18

I’ve run lein do exec -p scripts/server.clj, fig where fig is an alias

craftybones14:12:35

my jetty port also has :join? set to false

craftybones14:12:06

While the scripts/server starts, it doesn’t look like the alias executes

craftybones14:12:30

From what I can see, for some vague reason the scripts/server doesn’t finish executing, so lein doesn’t execute fig. However, the scripts server needs to connect to an instance of figwheel, websocket times out.

craftybones14:12:10

Any ideas anyone? The goal is simply to launch a custom server and figwheel with lein

Duck Nebuchadnezzar15:12:09

I'm in a similar boat as you, not having a single script to launch both. I typically launch my server and then in another terminal start figwheel, or I have emacs start figwheel when I connect.

craftybones15:12:04

Does it work if you use deps and clojure cli?

Duck Nebuchadnezzar15:12:52

I'm doing it using lein figwheel, so I don't know

craftybones15:12:35

lein figwheel? Or just lein with figwheel main? Lein figwheel is a different plugin

craftybones15:12:36

Any figwheel experts?

mikerod16:12:11

@srijayanth almost seems like you may have more of a lein question. But also it isn’t clear what the script is doing and also what the alias fig is doing.

craftybones17:12:02

@mikerod - sorry. The script simply starts a ring jetty server. The fig alias simply launches figwheel.

craftybones17:12:09

Hang on while I paste some

craftybones17:12:45

(require '[ring.adapter.jetty :refer [run-jetty]])
(require '[ring.middleware.defaults :refer [wrap-defaults site-defaults]])
(require '[ring.util.response :refer [resource-response content-type]])

(defn handler [req]
  (let [_ (println "the request is " req)]
    (or
      (when (= "/" (:uri req))
        (some-> (resource-response "index.html" {:root "public"})
                (content-type "text/html; charset=utf-8")))
      {:status  404
       :headers {"Content-Type" "text/html"}
       :body    "Not found"})))

(run-jetty
  (wrap-defaults handler site-defaults)
  {:port 4000
   :join? false})
(println "Started server")

mikerod07:12:09

@srijayanth well it wouldn’t make sense for this to work I think. Lein is going to launch separate JVM processes for each of these. The run jetty script should terminate after it completes. Which would end the jetty process as well. Then the fig starting would be a separate process and unrelated at that point.

craftybones07:12:50

Yeah. Figured that lein do is sequential anyway. I am going to do this programmatically instead of with lein

mikerod07:12:04

I think for what you are trying it needs to be done fully in one process - so yes programmatically.

mikerod07:12:20

Not sure I have a clear understanding of what you are doing still. But it’s common to use your own server with figwheel.

mikerod07:12:32

I do it al the time with lein-figwheel but it should have a similar method with figwheel.main

mikerod07:12:05

You should be able to just start a regular clj and then a fig cljs repl. And use your own server for serving your pages. Figwheel will use its for its code reloading web socket and cljs repl after that.

mikerod08:12:28

To do similar with lein, you could put the script stuff instead in an repl init config. Or just call it via repl once started

craftybones10:01:46

Thanks @mikerod - I am doing exactly what it is you are talking about. which is to have a single lein task that launches both the server and figwheel. The documentation figwheel provides on this specific point is only for CLI and not for lein. Do you have a handy repo by any chance that I can look at?

mikerod19:01:03

Haven’t been able to make example easily since only been answering from phone. Are you using cider?

mikerod19:01:32

cider-jack-in-cljs for example sets up a cmd to run like:

(do (require 'figwheel.main) (figwheel.main/start <options here>))

mikerod19:01:42

so that’s how you start it programmatically, which you could do any time after starting your server

mikerod19:01:01

to have lein do that automatically, just have to build it into some sort of init script lein will run for the process

mikerod19:01:18

the clojure CLI example just uses the -i flag, which is the same idea there I believe

mikerod19:01:26

so you call your fn in your script to start your server in something like https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L372 I believe

mikerod20:01:01

If you are starting with something like cider and launch 2 repl - one for clj and one “sibling” for cljs then you’d probably need to make this :init operation be able to only create the server if not already created (aka “idempotent”) . To avoid making multiple or attempting to when new repls are opened.

craftybones17:12:56

That’s the script/server.clj

craftybones17:12:38

the alias is simply

:aliases {"fig" ["trampoline" "run" "-m" "figwheel.main"]

craftybones17:12:02

I know why it doesn’t work and I also figured out that the only real way to do this is to programmatically call figwheel

craftybones17:12:18

programmatically launch the server and then figwheel

jjttjj19:12:47

Is it possible to use --watch and --repl together with cljs.main? Edit: actually now m issue seems to be that the windows cljs.jar isn't recognizing my git deps in deps.edn. Using clj from CLI with cljs.main seems to work with -r and -w but not together