Fork me on GitHub
#hoplon
<
2017-01-07
>
cdine06:01:53

Whats the idiomatic way to hook up a function when an element is added into the DOM?

thedavidmeister06:01:35

@cdine (with-dom el (prn “foo”))

thedavidmeister06:01:01

well, that’s a macro

thedavidmeister06:01:07

if you want a function specifically

thedavidmeister06:01:13

(when-dom el #(prn “foo”))

cdine06:01:54

Perfect, that worked like a charm.. that's what i was looking for... thanks much

cdine06:01:06

I couldn't find this in the docs..

thedavidmeister06:01:52

@cdine yeah unfortunately hoplon has some useful things that aren’t in the docs >.<

thedavidmeister06:01:04

if you’ve got a sec to update the wiki for the next person that would be awesome

meeli08:01:56

@alandipert having some troubles with svg/use with hoplon and firefox. firefox doesn’t want to render anything 😞

candera14:01:51

@meeli Did you sort? I make heavy use of SVG and use in my Hoplon app. IIRC it may be an XML namespace issue.

candera14:01:03

Ah, I see now that it’s one of the elements that I don’t use Hoplon for. https://github.com/candera/weathergen/blob/master/src/weathergen/ui.cljs#L2148-L2151

candera14:01:22

Namespaces might be the reason - I wrote that quite a while ago.

xssive22017:01:02

Hello. I have successfully created a hoplon-castra application that I would like to sell soon. There is one problem: I can't deploy it on a tomcat server. It yields an empty page and complains about TLDs? I scavenged the internet for working boot templates that can successfully deploy to tomcat, but it seems none of those currently exist. Not on the hoplon-demos, not Sean Corfield's hoplon-castra template... What am I doing wrong?

micha17:01:01

@xssive220 are you making a war file?

micha17:01:05

boot has some built-in things

micha17:01:16

the web and war tasks

xssive22017:01:26

I am using them

micha17:01:29

what do you mean by TLD, top-level-domain?

xssive22017:01:06

It seems to be a set of .tld files related to jars... altough I used the option to not unzip the jars

micha17:01:22

i'm not familiar with .tld extension

micha17:01:28

what does it do?

xssive22017:01:31

(uber :as-jars true)

xssive22017:01:05

I don't have a clue... But tomcat is scanning for those and doesn't find them... I could try tomcat 7 instead of 8?

micha17:01:28

you may need to make those files

micha17:01:40

i haven't used tomcat in a few years now

xssive22017:01:49

boot -d seancorfield/boot-new new -t hoplon-castra -n point-of-sale does not deploy after a boot make-war

micha17:01:28

perhaps compare the war file you create with a working example

micha17:01:37

and see if there are .tld files in the working one

micha17:01:16

looks like a tomcat 8 innovation

xssive22017:01:21

If I find anything useful I'll return the results for documentation

micha17:01:10

tag libraries

micha17:01:13

is what those are

xssive22017:01:19

unless tomcat 7 works... After all, I'm about to start my own business and having that POS app running would give me my first customer... Kudos for hoplon/castra/javelin, by the way. It's insanely easy

micha17:01:48

are you 100% decided on tomcat btw?

xssive22017:01:59

I could have found that myself probably, but I got frustrated....

micha17:01:25

a nice little embedded jetty server can be done very simply

xssive22017:01:29

Nope... But I have H2 database on board and would need a directory where it can scratch

xssive22017:01:05

build-jar didn't work either.. I filled handler.clj with :gen-class, but that didn't help

micha17:01:33

^^ you mean to make a jar you can run with java -jar?

xssive22017:01:37

I will need both options in the future, because running boot from an init script just doesn't look professional 🙂

micha17:01:53

i usually deploy uberjars now

xssive22017:01:55

that is what I would currently prefer

micha17:01:03

ok no problem

xssive22017:01:17

uberjars, that is

micha17:01:30

so to make an uberjar that you can run with like java -Xmx2g -jar project.jar

micha17:01:41

you will need a couple of things

micha17:01:58

the first thing you will need is an antry point for your application, a -main function

xssive22017:01:14

ah.... that isn't there, for starters 🙂

micha17:01:25

that function will start the embedded jetty server and initialize the application

micha17:01:00

the embedded jetty server will create a servlet internally and you can use ring to actually handle requests

micha17:01:30

the embedded jetty server is not complicated, i can make a demo

xssive22017:01:23

I have a straightforward setup with a route "app"

xssive22017:01:47

my (jar :main 'foo) antry will need to refer to a start funtion? -main can be in handler.clj?

micha17:01:03

assuming your ring handler is in app.handler/app

micha17:01:27

well you will need a two-stage approach, to keep the uberjar simple

xssive22017:01:33

hey I met that snippet earlier today... 😉

micha17:01:59

ha yeah i took it from the template

micha17:01:15

ok so assume that's in there and you can test it in the repl

micha17:01:22

and the server starts and does what you want

micha17:01:51

now you want to make an app.main namespace that will be compiled into a class that we can use as the Main class in the jar manifest

micha17:01:02

so we can have an entrypoint for java -jar

xssive22017:01:52

Ahhhh... I get it...

micha17:01:39

this little ditty will restrict the AOT compilation to that one namespace

micha17:01:57

because that namesopace doesn't :require any other ones

micha17:01:13

this is useful because there are all kinds of annoying issues you can run into with AOT compilation in clojure

xssive22017:01:20

What would happen otherwise?

micha17:01:24

so you want to avoid it whenever possible

xssive22017:01:30

basicallly dynamism gets hampered?

xssive22017:01:52

so 2-stage it is

micha17:01:53

well normally lisps interleave compilation and evaluation

micha17:01:05

when you AOT compile you interfere with that

micha17:01:32

ok so now in your boot pipeline you will want to do something like this

micha17:01:27

boot aot -n app.main uber jar -m app.main target

micha17:01:55

then you should be able to do

xssive22017:01:00

I see.. yeah that target task.. 🙂

micha17:01:07

java -Xmx2g -jar target/project.jar

xssive22017:01:18

is 2G advisable?

xssive22017:01:00

I'll get it going now , thanks a lot.

xssive22017:01:46

BTW, this means H2 cannot be embedded anymore, right? I'll need a separate database service?

xssive22017:01:05

But I should be able to get that running on the same jvm

xssive22017:01:35

I have my weekend cut out for me 🙂 Thanks again

xssive22018:01:55

It's working @micha , thanks a lot for the help

xssive22018:01:37

I'll try and get more involved in Q2 when I'm up and running, rolling out more apps for customers! 😉

micha18:01:05

i'm not familiar with H2, but maybe it can be embedded if it runs on the jvm

micha18:01:39

you can do this in your start-server fn or something

mynomoto19:01:36

@xssive220 I use a H2 db from a uberjar on code deployed on customers. It works.

xssive22019:01:49

@micha , @mynomoto : Thanks... I got it working, but not from an uberjar yet. Probably it needs to be in server mode instead of auto_server... I'll look at the links... thanks again! 🙂

wasserspiegel21:01:05

Is there a trick to do a dynamic :class on a div? [i.e. visible is a defc and (div :class [ (cell= (if (get visible id) ["coin" "up"] ["coin" "flip"] ..)) I get both up and flip classes on the div ] The same works fine with :css to position the div..

micha21:01:17

@wasserspiegel you mean like (div :class (cell= {:coin true :up visible :flip (not visible)}) ...

micha22:01:31

basically a map where the key are the class names and the values indicate whether to add or remove the class

wasserspiegel22:01:23

Yes, I hope I didn't ask the same thing last week I kind of have a deja vue. merci

meeli23:01:52

@candera can you explain more about the namespacing thing? i ended up just putting the paths inline because they’re not very complex, but i’d like to fix use and get it working. also, not really sure about xpath:src compatibility, i messed around in some codepens and saw that firefox didn’t like normal src at all 😞