Fork me on GitHub
#hoplon
<
2016-02-23
>
raywillig18:02:12

i have some hoplon in an iframe in another hoplon app. is there any way to get the iframe code to trigger something in the parent?

numberq19:02:05

I'm having some trouble understanding mkremote in Castra. The documentation says that there's an optional :url keyword to specify a POST address, but I don't think I'm formatting the function properly, and I can't find any examples of it online. How do I use this :url keyword?

numberq19:02:36

Actually, it looks like I figured it out, never mind!

numberq20:02:54

I must still be doing something wrong. I believe that the request is being sent to access the get-record RPC function in my handler on the server, but it continually returns a 403 Forbidden error. Should I be defining a POST route in my handler? I tried defining one at /, but I wasn't sure what to put in it so I just stuck a {:status 200} in there hoping it would work. It didn't. :P

numberq20:02:19

I'm using Compojure, fyi

micha20:02:21

@numberq: castra is middleware

roti20:02:22

@alandipert: defmethod do! and with-init! did the job

micha20:02:32

you don't make routes for it

roti20:02:32

thank you

micha20:02:03

@numberq: castra will handle any POST request that makes it to the middleware

micha20:02:13

it doesn't care about the route or anything

micha20:02:47

it shouldn't ever return 403

micha20:02:51

i don't think

numberq20:02:01

@micha: Okay, well I'm still getting a 403 Forbidden error regardless of if the route is there or not.

numberq20:02:27

Maybe my mkremote is wrong?

(def url "")
(def get-record
  (cas/mkremote 'myproject.handler/get-record record error loading
                {:url url}))

micha20:02:51

you should look in the browser dev tools

micha20:02:57

see the request it's making

micha20:02:06

something in your ring stack is returning 403

micha20:02:12

before it gets to castra

micha20:02:25

the dev tools will show you the body and headers

numberq21:02:35

Interesting, looks like its returning <h1>Invalid anti-forgery token</h1> for some reason

micha21:02:24

ring-anti-forgery

micha21:02:48

castra is not vulnerable to csrf

micha21:02:25

because it needs certain other headers to be present

micha21:02:36

which you can't do with a csrf exploit

micha21:02:51

so you don't need anti-forgery in front of castra

numberq21:02:49

Okay, I was using wrap-defaults from a tutorial which I think was causing the issue, because I'm no longer getting a 403 error. It's 404 now, though, with Not found as the response

micha21:02:43

i would start by removing everything but the castra middleware

micha21:02:11

and a 404 handler of course

micha21:02:53

(def app (-> (fn [_] {:status 404 :body "not found"}) (wrap-castra ...)))

numberq21:02:12

@micha: Okay, I'll try that at some point, since I have to go for now. Thank you for all the help!

roti21:02:11

is there a syntactic sugar in hlisp to select an element by id?

micha21:02:41

@roti: there isn't a single selector anywhere to be found in hoplon simple_smile

micha21:02:57

(.getElementById js/document "foop")

roti21:02:15

or js/jQuery, i guess

micha21:02:17

it's very rare to need anything like that

roti21:02:37

well, I am currently experimenting with jqueryui

roti21:02:59

and I need to bind button events with jqueryui actions

roti21:02:27

it's not frp-ish, i know, but I have no better idea at the moment

micha21:02:32

all of the jquery things i know of work with references to jquery objects instead of ids

micha21:02:51

or you can of course make gensym ids

micha21:02:59

and fish around for them later

roti21:02:45

take this case for example: you want to show a dialog when a button is clicked

roti21:02:28

so the button click handler, needs to call "dialog open" on the dialog dom node

roti21:02:48

pardon, dialog jquery object

micha21:02:50

yeah you keep a reference ot the dialog node

micha21:02:00

in the closure

micha21:02:22

or a cell that links the two

micha21:02:40

but ids work too

micha21:02:51

since you can generate random ones using (gensym)

micha21:02:11

but then if you're going to coordinate around the id you might as well coordinate around a cell

micha21:02:26

you still need to pass some information to both of the things

roti21:02:33

cell containing what value? it's just an event

micha21:02:46

it would contain the open/closed state

micha21:02:17

whenever the cell goes from false to true, .open() is called on the dialog

micha21:02:28

when it goes from true to false, .close() is called

micha21:02:42

now you can control it from formulas too, in addition to the user clicking on things

micha21:02:19

when the user clicks on the button it would do (reset! the-cell true)

roti21:02:53

yes, that would make it more frp like, I guess

roti21:02:14

i would also be able to get the dialog state easily

micha21:02:44

the real benefit is that you can now incorporate dialog state with other workflows

micha21:02:04

so some other condition could now cause the dialog to show

micha21:02:20

without altering the existing code that shows it when the user clicks on something

roti21:02:33

yes, decoupling essentially

roti21:02:57

thanks for the tip

micha21:02:48

i can't think of any place where i use ids to find things in the dom in hoplon apps

roti21:02:11

yes, the thing is, one has the tendency to do things the way they were learned, even though the "alternative way" is known and understood

roti21:02:37

funny thing, the brain

roti21:02:22

learns quickly, but unlearns hard

micha21:02:42

haha yeah

roti22:02:55

reminds me of a movie scene (likely with bruce lee), where he explains that you must empty your glass first, before starting to fill it with the new knowlegde