Fork me on GitHub
#hoplon
<
2016-05-11
>
leontalbot01:05:17

Hi guys! So I'd like to read a config file from clj file. hoplon-castra template creates an assets folder to store resources and nomally I would do (clojure.java.ìo/resource file.ext) but going to localhost:8000/file.ext I can see the file. How can I store the file so it is not visible/reachable by the browser and that I can still do ìo/resource on it? Thanks!

alandipert01:05:18

@leontalbot: there's resource serving ring middleware that's serving the classpath

alandipert01:05:41

you could either remove it, or make your own middleware that 404s for files you don't want to expose

leontalbot01:05:59

what is the simplest? are there examples?

leontalbot01:05:24

Thanks for answering btw @alandipert

alandipert01:05:12

maybe the exclusion middleware, if there are only a few files you don't want to expose

alandipert01:05:25

i'm not aware of an example tho, sorry

leontalbot01:05:40

In the lein world, I often see resources/public where only public is exposed to the web

leontalbot01:05:20

so you could call (io/resource "private/file.ext")

leontalbot01:05:17

where private is in resources folder.

leontalbot02:05:04

ok so :

(use 'ring.middleware.resource)

(def app
  (-> your-handler
      (wrap-resource "public"))

leontalbot02:05:12

it seems to work man!

leontalbot02:05:07

With this, I could read anything else in resources folder from my code, and only resources/public get exposed to the web

leontalbot02:05:56

Kind of surprised this is not used by default...

leontalbot02:05:31

Maybe I am the only one who needs this but I'd be surprised

leontalbot02:05:25

I find that useful for reading any static config files

leontalbot02:05:41

Maybe there are better practices??

alandipert02:05:10

@leontalbot: seems like a really good way to do it to me

alandipert02:05:18

if you want to make a PR to the template, i would happily merge

thedavidmeister05:05:46

hey, so i’m using sente instead of castra, just calling reset! in the callbacks that sente provides

thedavidmeister05:05:01

are there any known gotchas when not using castra?

thedavidmeister05:05:37

or should I be all good, as long as I’m careful to use cells to handle all the data propagation as it comes back from sente?

alandipert12:05:26

@leontalbot: thanks for the PRs - merged & pushed a new version of the hoplon-castra template

alandipert12:05:05

@thedavidmeister: should be fine, castra doesn't do anything special to cell behavior

alandipert12:05:29

@thedavidmeister: you may find dosync useful if you are integrating state from multiple places at the same time

alandipert12:05:47

it tends to be useful in situations when you're doing a series of reset! calls

alandipert12:05:57

like not over time, but within the same code block

alandipert12:05:24

no prob. would you be interested in helping maintain the templates? merging the occasional PR etc

alandipert12:05:33

cool simple_smile i'll add you as a collaborator

alandipert12:05:45

@leontalbot: you should have an invite to a github team that can admin the template repos. i also added you to the hoplon-castra and hoplon groups on clojars, so you can deploy to both groupids

alandipert12:05:21

thanks a lot for helping out!

leontalbot12:05:49

No prob. Be ready for some questions for the first deployment to clojars etc.

alandipert12:05:55

keeping the templates in good shape is important, as thats most peoples first interaction w/ hoplon

alandipert12:05:21

oh yeah, to deploy etc - update +version+ in build.boot and then boot build-jar push-release

alandipert12:05:31

note: after editing build.boot, commit the change

alandipert12:05:39

then, git push --tags

alandipert12:05:45

err i'll put in readme simple_smile

alandipert12:05:22

ok i added a bit about deploying, let me know if you have issues

dm313:05:57

@alandipert: I recall you had problems with Hoplon + CodeMirror - have you solved them?

alandipert13:05:32

@dm3: no, i never got it working

alandipert13:05:52

i think i got close though

dm313:05:12

ah, so it wasn't some unsurmountable problem

alandipert13:05:37

fortunately hoplon doesnt' do enough for anything to be unsurmountable lol

dm313:05:49

that's true

alandipert13:05:04

iirc the problem was a browser lifecycle thing

alandipert13:05:24

the with-init! was crucial, but i think after running codemirror might need an explicit repaint or something

alandipert13:05:44

i was going off examples of people creating textarea nodes dynamically and codemirroring them

devn17:05:01

I've been away from the front end for a long time, but I'm interested in Electron, just not the javascript part of it.

devn17:05:31

Any story there for hoplon?

piotrek18:05:12

Hi, I have a question about castra

piotrek18:05:54

From the docs and demos I noticed that the pattern is to establish some global cells for result, errors and loading and plug into them in your application code to get the data as it changes

piotrek18:05:02

but it looks like a singleton for me

piotrek18:05:19

like a one global single atom where my app gets the data from

piotrek18:05:43

I have a following usecase: I display a few small “reports” wigdets o a page

piotrek18:05:13

and each widget gets the data from the same server endpoint but with some different parameters (let’s say date ranges)

piotrek18:05:48

having a global cell for results from an endpoint like get-widget-data won’t work for me

piotrek18:05:00

is it possible to use castra in a more rq-async-rs mode where I could pass my result/errors/loading cells every time to my get-widget-data function on the client side?

piotrek18:05:48

I was thinking about using mkremote every time in my client side function with result/errors/loading cells passed to my function instead of using global cells

piotrek18:05:08

but I am not sure if mkremote is a costly operation and it shouldn’t be used like that

raywillig19:05:36

@piotrek: i’m not expert but it seems to me that what you’re proposing should work legally. Afaik mkremote just returns a function that binds the results of the RPC call to the cells you provide

raywillig19:05:36

however, i think there may be some other ways to manage what you want to do

piotrek19:05:56

@raywillig: thanks, I will try that

piotrek19:05:17

and maybe in the meantime @micha or @alandipert will have some suggestions too

raywillig19:05:25

the parameters that you want to pass to the castra endpoint are not cast in stone at the time you call mkremote

raywillig19:05:00

so each of your widgets could call the function returned from mkremote and the results will be bound to the state cell

raywillig19:05:36

do you envision invoking several reports simultaneously?

piotrek19:05:53

they will be displayed at the same time on one page

piotrek19:05:04

and they might call the endpoint from time to time

piotrek19:05:00

I would like to create a client local function like get-widget-data [date-from date-to result-cell errors-cell loading-cell]

piotrek19:05:17

so each time I could pass my cells explicitly

raywillig19:05:34

i think you could easily wrap mkremote to produce what you want

raywillig19:05:36

unless i’m misusing the trademarked phrase, Lisp Can Do It! ™️

micha19:05:13

@piotrek: when you have a rpc stub in the client, like for example (def f (mkremote ...))

micha19:05:28

when you call f, f returns a jQuery promise

micha19:05:46

you can use that to obtain the result via callbacks

piotrek19:05:11

I really like the pattern with the cell-trio simple_smile

piotrek19:05:24

because I also design my elements so they accept the cell-trio

micha19:05:35

(-> (f ...) (.then (fn [result] (doit result))) (.fail (fn [ex] (doit2 ex))))

micha19:05:43

yeah you can do that too

piotrek20:05:05

so I have a function which creates those cells, calls my function with them and pass the cells as attributes to my elem

micha20:05:15

yeah that totally works

micha20:05:32

like local rpc endpoints, anonymously provided to the component

piotrek20:05:33

then I can easily manage the elem by showing loaders based on loading cell, errors and finally the data

micha20:05:04

we do the same thing in our application too

micha20:05:50

you could do it in such a way that you just call mkremote one time

micha20:05:06

like this:

micha20:05:34

(let [rpc-stub (mkremote ...)]
  (defn get-record [...]

micha20:05:07

actually no

micha20:05:11

haha that's nonsense

micha20:05:29

but i am confused by what you put there

micha20:05:39

i think you want like a factory

micha20:05:58

where given the cell triple you return a function

piotrek20:05:54

I want to have a plain function which gets my function params (like entity id etc.) plus my cells trio

piotrek20:05:05

please, take a look at my second snippet

piotrek20:05:11

it shows how I use such functions

piotrek20:05:44

right now I don’t have any castra calls (working on this right now) but I just mock the server by using with-timeout to simulate network latency 😉

micha20:05:50

i think i might want to use the promises there

micha20:05:04

instead of calling mkremote many times

micha20:05:25

i'm worried about memory leaks

micha20:05:32

but maybe that's not an issue

micha20:05:40

one sec i will check the code

piotrek20:05:09

Do you mean creating a stub once (and store it globally) and then use jquery promise to put data into my cells trio?

micha20:05:42

yes, but i think it looks fine to use mkremote in the way you're using it, too

micha20:05:01

i just checked and it doesn't look like there will be any issues there

micha20:05:16

it's basically doing the promise things internally anyway

micha20:05:23

same as what you would do

piotrek20:05:26

I will use it like that then

piotrek20:05:35

@micha: thanks for the feedback!

micha20:05:57

looks good to me!