Fork me on GitHub
#hoplon
<
2020-02-26
>
rlander21:02:30

So what's the idiomatic way of breaking a non-toy Hoplon app into namespaces? Most of the examples I found involved a single namespace.

rlander21:02:47

I just ported the realworld app (https://github.com/gothinkster/realworld) to both learn how Hoplon works and to contribute back with a "reference". Anyone willing to take a look at the code?

alandipert21:02:51

i think usually there's an entrypoint element that's basically a tabset, and namespaces follow from how that top level element is structured

rlander21:02:19

@alandipert so each "page" would be a separate ns?

alandipert21:02:07

this is one area where hoplon offers a lot of flexibility so i'm not sure there's one true approach

rlander21:02:11

how about top level cells (state)? Should they live in a separate ns, like myapp.state or within the page ns?

alandipert21:02:18

since the linkages between cells are usually automatic, explicit structure isn't required

rlander21:02:59

I ended up doing everything in one single file, the entire 900 lines. haha. Doesn't look as bad as it sounds.

alandipert21:02:10

there can be a top-level state, usually it contains the route and info related to the URI

alandipert21:02:18

then usually instances of elements have a bunch of anonymous let-bound cells

alandipert21:02:44

i'm sure it's awesome, maybe one of the greatest things about hoplon compared to other frameworks is you can do it all in a single file

rlander21:02:54

Yeah, I tried to used scoped cells as much as I could so that most elements could be re-usable.

flyboarder21:02:05

I only use global state for things that should be global, ideally state is scoped to a page or element

flyboarder21:02:34

with element state you have the option of a local let scoped cell or passing one in via an attribute

alandipert21:02:54

oh yeah, cell attributes, a key pattern

flyboarder21:02:57

so often we use (:state attr (j/cell nil))

rlander21:02:28

That's a very useful idiom, thanks.

flyboarder21:02:44

this pattern lets you have local default state while also accepting external state for reusability

rlander21:02:01

Are you guys interested in adding this to the canonical realworld repo? It's fully working (based on shadow-cljs and retiit router though).

rlander21:02:37

@flyboarder Yeah, I tried to keep global state only for shared cells.

rlander21:02:39

I'm coming from many years of reagent and re-frame apps so maybe some of the code looks reagent-ish.

flyboarder21:02:09

always open to more demos, feel free to open a PR for the demo repo

rlander21:02:15

@flyboarder I was thinking of adding to this repo: https://github.com/gothinkster/realworld

👍 4
alandipert21:02:52

@rlander skimming the code, looks great. 42 bonus points awarded for dosync use

rlander21:02:56

Thanks! Should've used more dosynchad I added a loading cell.

alandipert21:02:50

makes me wonder about a helper for nested divs like (divs [["outer-class"] ["inner-class"]] ...inner-children) to compete for line count better simple_smile

alandipert21:02:46

looking at the elm version... so many files 😱

rlander21:02:18

@alandipert hmm yeah, I didn't even try to reduce repetition and it's already besting the re-frame implementation by ~150 lines. But yeah, that kind of helper would be useful!

alandipert21:02:49

well, maybe it would hehe. it also obfuscates

rlander21:02:52

I'm also a little worried about the bundle size. The last build got to ~700kb.

alandipert21:02:44

oof, thats with advanced and stuff?

rlander21:02:52

BTW, using shadow-cljs & Hoplon together was a blast.

rlander21:02:30

Yesm with advanced on. Shadow-cljs has a report command that shows all dependencies by size.

alandipert21:02:37

not to suggest hoplon PR work for you 😉 , but i don't think anyone's ever written an experience report about that combo

alandipert21:02:53

anyway i would upvote it

rlander21:02:56

@alandipert I was going to write about the experience anyways, no worries 🙂

rlander21:02:26

They go really well together since through shadow-cljs I am free to use any JS lib that's in npm.

rlander21:02:38

BTW, I only used shadow-cljs because I could not find recently updated boot template.

rlander21:02:56

It's nice to know that it is flexible enough to work well with a build tool that didn't even exist when Hoplon was created, though.

rlander21:02:27

As someone who's coming from years of React/Redux/reagent/re-frame, I really enjoyed working with Hoplon.

rlander21:02:48

So, do I keep it a one-file project?

alandipert21:02:49

one-man project = one-file project imo 😆

😁 4
alandipert21:02:56

i love keeping huge things to one file if i can

alandipert21:02:04

other programmers tend to object

alandipert21:02:37

modern editors can split files into conceptually separate files with window-splitting technology

micha21:02:11

what is this sorcery

micha21:02:30

i have separate files on separate computers in separate buildings

micha21:02:41

now you say i can do some craziness in my editor?

alandipert22:02:14

C-w v ®️

😀 4
rlander22:02:08

My concern is publishing something not idiomatic as a Hoplon reference.

alandipert22:02:50

no concerns here. if it works for you, then it's idiomatic as far as we're concerned

alandipert22:02:04

and if it didn't work for you, you woudl use something different 😄

rlander22:02:50

Awesome. I'll clean it up, add a repo, add to the demos and post the link here.

alandipert22:02:00

i feel like this is maybe why people were always a little weary of hoplon, we never described (or prescribed...) any particular high level architecture in concrete terms

alandipert22:02:17

but that was supposed to be a feature, that the implementor would have full control there still

micha22:02:53

yeah it's just a clojure program at the end of the day, right?

micha22:02:28

you can organize any clojure program in different ways by factoring it into namespaces

micha22:02:43

probably isn't any one best way to do that

rlander22:02:06

For someone just getting started this can definitely be a problem

rlander22:02:33

Most people think hoplon is this monolith thing that can only be used with .hl files, boot and castra and it's actually the opposite.