Fork me on GitHub
#re-frame
<
2016-05-19
>
mikethompson01:05:38

@lewix: it sounds like Luminus should be your starting point - http://www.luminusweb.net/

mikethompson01:05:18

Not for the language, but if you are seeking some overall structure about getting started with a web app in clojure

heeton13:05:44

Looking for some guidance with a larger app - https://github.com/Day8/re-frame/wiki/A-Larger-App - If I’ve got multiple db.cljs files setting up multiple databases, as suggested, how do you switch between those when using different “panels”. Is anyone here actually using that approach? I can’t seem to find any examples online and my experiments are failing me a bit…

escherize13:05:27

multiple db's you say?

heeton13:05:50

I’m not fully understanding how the DB is stored by re-frame. Can I just fire off a new handler which returns my new DB and everything switches over to that?

escherize13:05:27

so, the db at its most basic is just something like

(r/atom {:debug? true})

escherize13:05:36

so, you can add keys to that map however you want.

heeton13:05:54

@escherize: Have you seen the suggestion for larger apps here? https://github.com/Day8/re-frame/wiki/A-Larger-App

escherize13:05:26

I believe panel1.db namespace would just be functions that are for panel1 that operate on the db.

heeton13:05:41

I assume the suggestion is to have differently namespaced DB atoms

escherize13:05:53

No, I don't think that is the case.

heeton13:05:41

Oh, ok. I’ve not come across db-functions kept in that db namespace in any examples, is that a common approach?

escherize13:05:46

I'd probably do something like this:

(r/atom {:panel-1 {:name "George"}
          :panel-2 {:name "Oren"}})

heeton13:05:55

Just seen it used to define the initial state

escherize13:05:07

I never do that.

escherize13:05:32

I had a medium/large re-frame app with just subs.cljs, and handlers.cljs.

escherize13:05:47

and did init in core.cljs (dont reccomend).

escherize13:05:19

so the handlers ns was about 600 loc - but It never bothered me enough to split them up.

escherize13:05:01

Anyway that's just housekeeping imo - the key to reframe is that you have handlers that are (ideally/usually) pure functions operating on a single db, and returning new versions of it.

heeton13:05:53

It’s not the size, per se, this app is a collection of different utilities for our admin team to work with. Was getting annoyed with the handlers all being in one spot, so started to give them virtual namespaces, then saw that wiki article but couldn’t follow the splitting of db.cljs

escherize13:05:56

call it register-signup or signup/register doesn't make a big difference imo. When it comes to panelN/db.cljs

escherize13:05:36

I would think db.cljs could require panel[1-N]/init and merge the initial data together as it saw fit.

mikethompson13:05:55

@heeton: the different db.cljs generally just hold schema. or perhaps initial values. Stuff related to the model/database. They do not actually contain a database itself. There is only one of those and that's hidden away in re-frame itseld.

escherize13:05:00

I can see how you got that assumption though, @heeton.

heeton13:05:02

@mikethompson: That’s what I was trying to ask about. If you have multiple db namespaces, does that imply that you’ve got different sets of initial values that you’re swapping the DB out for as you switch panels?

heeton13:05:11

Though as Escherize said, probably not, it’s just for different db functions

escherize13:05:56

You could have your initial database split into those namespaces.

mikethompson13:05:13

It depends. But you probably wouldn't be swapping dbs. You would be more likely updating part of it.

heeton13:05:15

Then merge them together as you initialize?

escherize13:05:25

That's what I would do, @heeton

escherize13:05:52

Well, if you forced me to split up my db-init function...

heeton13:05:10

Yea, I personally don’t think that sounds very clear, probably wouldn’t myself either

escherize13:05:51

(ns db.init
  (require [panel1.db :as panel1]
           [panel2.db :as panel2]
           [panel3.db :as panel3]))

(defn init []
  {:panel-1 (panel1/init)
   :panel-2 (panel2/init)
   :panel-3 (panel3/init)})


(register-handler
 :init-db
 (fn [& _]
   (if-let [frozen-state (find-app-db-in-local-storage)]
     frozen-state
     (init))))

mikethompson13:05:51

If it was necessary, you might be dispatching various initialize events in here: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/core.cljs#L30-L34

escherize13:05:50

Usually I check local storage before init-ing the DB, since I tend to save to ls on "important" events.

heeton13:05:11

Cool, thanks both

heeton13:05:57

Realising I can actually swap out the entire DB contents for a new panel’s #init’ed data too

heeton13:05:32

(right now, the panels are totally separate) But that’s probably not a good long-term idea because we’ll want to add some sort of top-level data at some point

escherize13:05:36

I think a problem re-frame dodges which is shared by a lot of clojure, is updating nested data inside atoms can be tough.

heeton14:05:12

So @escherize you do all the database manipulation stuff directly in your handlers. Know of people just deferring to db namespaced “updater” functions? Has anyone talked about that approach and if it’s good or needless?

escherize14:05:23

I know that people use that. I was working on that large project by myself. I could see if I had a team working on it how I'd like to split things up, since it'd make it easier to see what has been changed/added.

escherize14:05:40

If I'm working on the payments page, then I dont care if you change most anything in ourproject.signup/*.

escherize14:05:05

unless i rely on your data and you change that.... (how could you???)

mattsfrey14:05:58

Is there any known method or util/library to view your entire app-db in object form? Like print it out in the js console and be able to look at each section?

escherize14:05:14

There are a few

escherize14:05:43

I came up with one, heh. but it's not the best one

escherize14:05:52

link incoming

escherize14:05:13

That is a good one.

heeton14:05:15

So I have a ‘debug’ component at the foot of my apps

heeton14:05:48

It comes with a CSS file to style the results, and then just spits out a big table of html when you provide your db value.

escherize14:05:11

> look in wiki for FAQ.

escherize14:05:39

1 sec - adding to resume: http://take.ms/73unv

escherize14:05:59

I am sleep drunk..

mattsfrey14:05:10

thanks guys, I’ll check this out