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.
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?
i think usually there's an entrypoint element that's basically a tabset, and namespaces follow from how that top level element is structured
@alandipert so each "page" would be a separate ns?
it could be
this is one area where hoplon offers a lot of flexibility so i'm not sure there's one true approach
how about top level cells (state)? Should they live in a separate ns, like myapp.state
or within the page
ns?
since the linkages between cells are usually automatic, explicit structure isn't required
I ended up doing everything in one single file, the entire 900 lines. haha. Doesn't look as bad as it sounds.
there can be a top-level state, usually it contains the route and info related to the URI
then usually instances of elements have a bunch of anonymous let-bound cells
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
Yeah, I tried to used scoped cells as much as I could so that most elements could be re-usable.
I only use global state for things that should be global, ideally state is scoped to a page or element
with element state you have the option of a local let scoped cell or passing one in via an attribute
oh yeah, cell attributes, a key pattern
so often we use (:state attr (j/cell nil))
I'm still going to clean this up, but here it is: https://gist.github.com/rlander/e971880d86ad8ccb665ab69a0eb731aa
this pattern lets you have local default state while also accepting external state for reusability
Are you guys interested in adding this to the canonical realworld repo? It's fully working (based on shadow-cljs and retiit router though).
@flyboarder Yeah, I tried to keep global state only for shared cells.
I'm coming from many years of reagent and re-frame apps so maybe some of the code looks reagent-ish.
always open to more demos, feel free to open a PR for the demo repo
@flyboarder I was thinking of adding to this repo: https://github.com/gothinkster/realworld
@rlander skimming the code, looks great. 42 bonus points awarded for dosync
use
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:
Thanks! Should've used more dosync
had I added a loading
cell.
looking at the elm version... so many files 😱
@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!
well, maybe it would hehe. it also obfuscates
I'm also a little worried about the bundle size. The last build got to ~700kb.
oof, thats with advanced and stuff?
BTW, using shadow-cljs & Hoplon together was a blast.
Yesm with advanced on. Shadow-cljs has a report command that shows all dependencies by size.
not to suggest hoplon PR work for you 😉 , but i don't think anyone's ever written an experience report about that combo
anyway i would upvote it
something like this: https://gist.github.com/rlander/3081f3703ea9cfed3129e8afcc94bedb
@alandipert I was going to write about the experience anyways, no worries 🙂
They go really well together since through shadow-cljs I am free to use any JS lib that's in npm.
BTW, I only used shadow-cljs because I could not find recently updated boot template.
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.
As someone who's coming from years of React/Redux/reagent/re-frame, I really enjoyed working with Hoplon.
So, do I keep it a one-file project?
That's a very useful idiom, thanks.
one-man project = one-file project imo 😆
i love keeping huge things to one file if i can
other programmers tend to object
modern editors can split files into conceptually separate files with window-splitting technology
what is this sorcery
i have separate files on separate computers in separate buildings
now you say i can do some craziness in my editor?
C-w v ®️
My concern is publishing something not idiomatic as a Hoplon reference.
no concerns here. if it works for you, then it's idiomatic as far as we're concerned
and if it didn't work for you, you woudl use something different 😄
Awesome. I'll clean it up, add a repo, add to the demos and post the link here.
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
but that was supposed to be a feature, that the implementor would have full control there still
yeah it's just a clojure program at the end of the day, right?
you can organize any clojure program in different ways by factoring it into namespaces
probably isn't any one best way to do that
For someone just getting started this can definitely be a problem
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.