Fork me on GitHub
#clojurescript
<
2018-04-16
>
bumblehead05:04:58

hello I'm visiting here to ask a question about reagent https://github.com/reagent-project/reagent-frontend-template

bumblehead05:04:23

I'm able to build a template app using this repo and I'd like to build a single page app

bumblehead05:04:54

and I want to know how to generate an spa from a reagent app

bumblehead05:04:23

so that I can deploy static html/js/css to gitlab pages

soulflyer06:04:22

https://github.com/Day8/re-frame is made for this. Lots of good stuff going on there. Also https://github.com/Day8/re-com might be worth a look. The demo page at https://re-com.day8.com.au/ is basically an spa showing off all the neat things it can do.

bumblehead06:04:05

I'll look at re-frame, but do I need to use a different system on top of reagent in order to generate static assets?

soulflyer06:04:34

Not sure what you mean. If you are talking about the html, then probably not. It all gets generated by reagent. The actual html is usually just some includes and an empty div for reagent to write to.

bumblehead06:04:03

I'm extremely novice... and am using this command currently "lein cljsbuild once min"

bumblehead06:04:02

it appears directory is generated, resources/public/

bumblehead06:04:23

and I would be able to deploy this directory if it included and html file

bumblehead06:04:45

but inside is only css/site.css

soulflyer06:04:09

ah right. Not sure where the index.html file is in a pure reagent project. Mine is in app/dev , put there by my descjop template generator. Have a poke around, it should be there somewhere.

bumblehead06:04:25

i kept doing this command ls ./*html, ls ./*/*html, ls ./*/*/*html going deeper each time

bumblehead06:04:33

no html file is there..

bumblehead06:04:00

I see the project.clj file defines a 'min' build

bumblehead06:04:58

I see that it directs js files to target/cljsbuild/public, but there is nothing in the ":min" definition describing .html

soulflyer06:04:51

I have a copy of the reagent git repo and there is an index.html file under site/public

soulflyer06:04:46

Sorry I don't recall how that particular demo served up the html tho

soulflyer06:04:07

yeah, that's it

muld3r08:04:15

Hi clojurians, I've a quite simple question regarding a react wrapper in cljs (rum + citrus). Coming from a react + redux background, I'm a bit confused about best practices of state management with rum + citrus. With redux you're using a global 'source of truth' and bind actions/reducers to your store. In 'citrus' though it's not obvious if a single reconciler should be passed from root context to each component down the dom-tree or if it makes sense to create more than one reconcilers. Thanks for your time!

alex.gavrisco08:04:45

Hi, I'm playing with CLJS and electron and I'm wondering why js/process and (js/require process) are different objects. I'm expecting that js/process is the same global process object I access from node REPL. However in release build js/process isn't what I'm expecting (e.g. doesn't have version property, only env). Here's my configuration https://github.com/Alexx-G/cljs-electron/blob/master/project.clj Using process via js/require solves my problem, but I want to make sure that I'm doing the right thing.

skrat10:04:59

@cdepauw if you generated that project with reagent or figwheel template then there is an html file. If there isn't, you need to create it manually, include css and scripts and call your app's entry point

pesterhazy10:04:56

@alex.gavrisco have you tried (i) the same thing from pure js and (ii) accessing js/window.process?

juhoteperi10:04:38

@alex.gavrisco Probably https://clojurescript.org/reference/compiler-options#process-shim is enabled so ClojureScript compiler will set process.env = {NODE_ENV: "production"}, if you are using Cljs with non-Node environment where process is set, you should probably option this value to false

juhoteperi10:04:58

(The option will default to false when using :target :nodejs)

pesterhazy10:04:02

:target :nodejs is sensible for Electron anyway, right? @juhoteperi

juhoteperi10:04:18

I don't know.

pesterhazy10:04:30

(also global.process should work in any case... I think)

pesterhazy10:04:37

or maybe not?

pesterhazy10:04:29

not sure if it should be window or global actually...

juhoteperi10:04:31

process-shim will override global.process.env so it doesn't matter if one uses js/process or (.-process goog/global)

👍 4
juhoteperi10:04:55

js/window and goog/global are same thing for browsers at least

alex.gavrisco12:04:04

Thank you folks! I'm not sure if in electron's case :target :nodejs is the right thing, however disabling process-shim helped.

mkvlr13:04:16

can someone recommend a clojurescript or javascript library for terminal emulation? At the moment I’m less interested in ansi coloring but more about cursor movement.

john14:04:40

no prob. But if you don't need to actually deal with readline stuff, you'd probably have a far easier time doing it with a "fake terminal" setup: https://github.com/avgp/terminal.js

mkvlr14:04:28

I only want to display output, don’t need input handling

john14:04:29

and if all you want is to simulate a simple repl stuff, you can just copy how replumb does it. Looks like they bring in jqconsole: https://github.com/Lambda-X/replumb/blob/master/repl-demo/browser/cljs/replumb_repl/console.cljs

john14:04:12

You might want to just try a simple html element then, and massage it to look like a terminal then.

mkvlr14:04:16

that’s done already. So far we just have a regex for carriage return, but it’s not working for all cases, e.g. wget…

mkvlr14:04:47

thanks, will take a look at replumb

bhauman13:04:58

So I'm currently working on a figwheel.main and I'm really considering having cljs build configs be in separate files.

bhauman13:04:59

this allows build config reuse

bhauman13:04:35

I am also considering using meta data to allow figwheel specific config

bhauman14:04:12

where the metadata will be merged with a figwheel-main.edn file

mkvlr14:04:35

@bhauman why not put the fighweel data as namespaced keys on the same map?

bhauman14:04:09

the compiler warns about unkown keys

mkvlr14:04:28

oh, alright

bhauman14:04:30

this makes the config less reusable

bhauman14:04:35

other tools would have to remove the extra keys

bhauman14:04:08

or if you had a compile script you would have to remove them

mkvlr14:04:58

I thought it was generally bad practice in clojure to care about what else is in a map

mkvlr14:04:20

which is why spec doesn’t support this use case

bhauman14:04:31

yeah trade-offs

bhauman14:04:53

figwheel has great config checking precisely because of this trade off

mkvlr14:04:23

yeah, it does make sense sometimes

bhauman14:04:39

and the compiler just warns in this case

mkvlr14:04:23

then I guess the metadata approach is good

mkvlr14:04:36

looking forward to fighweel.main btw

👍 4
sarna14:04:36

hey, what would you use for making a cli app? nothing to do with the browser, startup time matters. I've tried this https://medium.com/@shakdwipeea/building-command-line-applications-using-clojurescript-and-nodejs-a-beginners-tale-32a0a420fac4 but it sounds really cumbersome and the repl is slow

sarna14:04:48

thanks! I'll try it

sarna15:04:58

I'm getting an error. I've got the same error when trying to install planck. any ideas what could it mean? cp: cannot stat 'PREFIX/example-deps.edn': No such file or directory

mfikes15:04:34

@U9QTVPNHX This smells like a bad or botched install of the clojure tool

sarna15:04:36

@U04VDQDDY I reinstalled it, same thing

mfikes15:04:17

Need more context on where you are seeing that error. Perhaps put a transcript in a gist

mfikes15:04:12

Not enough context. Show how you install clj.

mfikes15:04:39

There is also a #tools-deps channel that might have info on this failure mode.

soulflyer15:04:51

Any reason for using clojurescript rather than clojure? I write small command line utilities using clojure and lein bin now.

Garrett Hopper15:04:01

@U0C8489U6 I'm glad it worked for you. What exactly is that repo for?

mfikes15:04:38

@U0E3H1J5Q If you really want to reduce launch latency, you can get ClojureScript-based approaches to run in milliseconds, while Clojure-based solutions can still take on the order of 1 second or more.

sarna15:04:25

@U04VDQDDY thanks for help, it was linuxbrew who borked my installation. it somehow installed a second clj and broke both 🤷

Garrett Hopper15:04:29

Being able to use arbitrary node packages can also come in very handy when writing simple utility scripts.

sarna15:04:11

exactly, clojure startup time is an annoying paper cut when you launch that thing often

soulflyer15:04:21

@U04VDQDDY Ah ok. Not yet felt the need for that much speed.

mfikes15:04:43

@U0E3H1J5Q Right. It also depends on what your script does. For example: If it is going to run for 15 seconds or more, then why bother trying to save 1 second? But if it is a little utility that you interact with (and it would otherwise run quickly), then that 1 second could become annoying.

mfikes15:04:56

Launching a REPL to evaluate a form has now crossed over to where clj is pretty much fast enough for me. But lein repl was too painful.

soulflyer15:04:19

Yeah, most of mine are wading through a collection of pics doing something to each. 1s gets lost in that

mfikes15:04:54

For that kind of thing, Clojure can be advantageous because you can multi-thread. 🙂

richiardiandrea15:04:13

@ghopper it is for a hackathon, a simple utility for an event sourcing framework. Nothing fancy :)

sarna15:04:17

how do you use this build tool? without arguments? it fails with java.io.FileNotFoundException no matter if I feed it the file.cljs or not 😩

john14:04:59

@bhauman are there alternatives to this metadata approach?

john14:04:30

So compiler options could be stored as dev.edn, min.edn, etc

bhauman14:04:36

@john not an alternative that would allow all tools to just use the options file

bhauman14:04:51

not that I can think of

bhauman14:04:23

but yes the idea is that the builds would be in files and that would allow for reuse

john14:04:49

Could fighweel's config just point to those files?

bhauman14:04:18

figwheel would find the files

bhauman14:04:27

build.cljs.edn files

john14:04:37

Or do you not want to couple the fighweel build confs into one file?

bhauman14:04:12

it just seems that the config is useful in contexts beyond figwheel

bhauman14:04:32

and you can slurp it in, in all the other contexts

john14:04:39

That would be nice

john14:04:54

does metadata work in edn?

john14:04:56

so I guess the alternatives would be having a primary, alternative file, which generically defined a set of build configs. Or an "extra" file for each compiler options file. Seems like metadata would be cleaner...

john14:04:32

are there instances where you'd want to use different co.edn files but one common extra_options.edn?

john14:04:05

Probably not, right? Because you'll usually want separate watch dirs for each build

john14:04:18

potentially

john14:04:02

Actually, compiler options takes a :watch dir. Is that different than figwheel's watch dir?

john14:04:24

creating a centralized config file gets us right back into coupling all the configs into a central place... On the other hand, having my project explode into 50 little config files doesn't seem like a good idea either... metadata seems like a good compromise, but I just wonder what those would look like if the metadata sets started to look "big"?

john14:04:39

And what happens if/when all tools take this route?

john14:04:17

For configs not expected to be applicable across the whole ecosystem, metadata keys should probably be namespaced

petr.mensik15:04:18

Is there a way how to include hidden files into uberjar build? I need to package some AWS config which has to be in .ebextensions folder in the root of deployed JAR file. I tried both putting it directly to resources and to resources/aws_config with resource-paths unpack but with no resuilts 😕

joelsanchez15:04:55

I think cljs should provide a standard way of creating namespace-qualified keywords programatically right now it's fine if I do ::my-keyword, but for achieving the same with an expression I have to do: (ns-kw (str "my-" "keyword")) this results in the same thing (`::my-keyword`). ns-kw is:

(defmacro ns-kw
  [input]
  (let [caller-ns (-> &env :ns :name str)]
    `(~'keyword ~caller-ns ~input)))

joelsanchez15:04:13

...and it's cumbersome

dnolen15:04:51

it’s not obvious how this should work - so unlikely without a lot of thought

dnolen15:04:23

a macro interface is not really programmatic

dnolen15:04:30

and the current ns is not a thing at runtime

joelsanchez15:04:53

I understand. at least I have the macro 🙂

petr.mensik15:04:07

FYI, I've solved it with jar -uf target/my-jar.jar -C resources/aws_config .ebextensions in my bash build script (luckily I have one). But I am still not sure how to do it with lein

mac20:04:10

I understand why class might not make sense in general in ClojureScript, but how would one implement dispatch based on derived relationships without it, like https://clojure.org/reference/multimethods#_isa_based_dispatch

john21:04:54

@mac you want to implement something like multi methods?

john21:04:37

or strictly class based multi methods?

john21:04:13

I mean, dispatching on class?

john21:04:03

oh, I see what you mean

john21:04:20

like, what are some examples

mac21:04:58

@john Well, one would the example at https://clojure.org/reference/multimethods#_isa_based_dispatch which deals with geometric shapes

john21:04:31

right, it's pretty ad hoc

john21:04:25

alex miller commented recently that most folks generally don't do "heirarchy" type things

john21:04:39

I guess it's like core logic or STM or other power tools. You usually only really need them on rare pain points

john21:04:17

like rendering massive shape hierarchies or whatnot

mac21:04:44

@john Not shapes as such, but I am both "evaluating" and rendering exactly such a hierarchy. Right now I have settled on maps with a :type key.

john21:04:13

Sounds reasonable

mac21:04:20

@john But would be nice if something like class existed, so I wouldn't have to have a bloated dispatch function the deals separately with domain data structures (maps) and primitives.

john21:04:14

I'd use the derive/isa/maps tools to just explore your domain. Then settle on protocols once you need performance.

john21:04:59

you can dispatch on class using the host fast path with protocols

john21:04:13

and deftype

mac21:04:53

@john Yeah, hope protocols are flexible enough

john22:04:50

What kind of performance do you need?

john22:04:12

is it a simulation?

mac22:04:41

@john Right now I don't think the performance is critical. It is not real-time or anything like that.

john22:04:17

multi methods and maps are going to be the most flexible, I think

mac22:04:02

@john Yeah, that is my current thinking too.

john22:04:40

just add a little data to your maps and lean on multi methods to manage your hierarchical dispatch. You should probably only have to futz around with the isa/prefer-method stuff if you need to override some default order

mac22:04:18

@john Thanks for the input.

👍 4