Fork me on GitHub
#re-frame
<
2018-06-25
>
caleb.macdonaldblack05:06:47

What would be the idiomatic way to pass something outside of the app db into a sub? For example a property on the dom.

Hukka06:06:48

Can't say I really know the answer, but wouldn't that cause a problem when the data you want changes, but because there are no db changes, the subscription will never update? My first hunch would be to somehow get the data you are after into the db

Hukka06:06:12

Perhaps even by polling

kennytilton13:06:03

Pass from where outside? And what is “a sub”? If outside is a container component and sub is a subcomponent view, then just pass the value in the vector specifying the sub.

kah0ona08:06:31

Hi guys, i’ve got a interceptor which i’d like to put in each handler. Is it possible to add it globally?

kah0ona08:06:43

Or should it be added to each handler by hand

joshkh09:06:30

i'm trying to shift my thinking towards a url-driven re-frame app. in my scenario, a user can go to a url to list files in a folder, but first the user needs a token. how do people normally handle this scenario from a routing perspective? my solution: secretary dispatches the event, the event checks for the condition, if it's not met then the event gets queued using a combination of re-frame-forward-events-fx and re-frame-async-flow-fx until a token is fetched. does that sound sensible?

lwhorton19:06:52

this is always a tough problem. honestly i find url-driven apps to be confusing if they’re not server-side rendered.

lwhorton19:06:23

something like rails / django / pheonix, etc. makes it super easy to do url-driven apps, but those aren’t SPAs. the impedance is miss-matched

joshkh09:06:18

(i know that kee-frame can solve this problem but i'd prefer to do it myself)

ingesol11:06:14

It's a difficult problem to solve. I assume you first want to get the token from the server, then get file list from server?

ingesol11:06:10

You could have a look at interceptors. Put an interceptor on the "list files" event, that stores the original event and forwards to the "fetch token" event. or did you already try that?

ingesol11:06:49

This particular problem doesn't get that much easier with kee-frame by the way. State machines and ordering of events is an unsolved problem in both re-frame and kee-frame 🙂

troglotit11:06:41

btw, as this PR is closed https://github.com/Day8/re-frame-async-flow-fx/pull/20 I was able to have some kind of ordering of events: I assign correlation-ids (http://hilton.org.uk/blog/microservices-correlation-id) to my events, I have this effects factory for my “request” effect:

joshkh11:06:21

yup, i think we're tackling it in similar ways. basically i want a drawbridge in my app that parks any events fired by sub urls if something is missing from the db that requires user intervention (authenticating)

joshkh11:06:29

re-frame unrelated, but has anyone been successful using bidi with a # prefix in the browser? this seems to be an issue? https://github.com/juxt/bidi/issues/120

ScArcher16:06:55

Can someone help me understand how to bind a set of radio buttons to a database value?

kennytilton16:06:11

I think the only difference, as I said, would be actual radio stuff having different events.

kennytilton16:06:54

Note that my example is trickier than usual because it treates re-selecting the same sort to mean “sort in the opposite order”.

kennytilton16:06:43

I have a pseudo radio group, if that helps. I have each item (<sub [:job-sort]) where :job-sort is the DB value driven by the group. And, yeah, it is a global option so a very short path. 🙂

ScArcher16:06:10

That would be helpful. I’m pretty new to reframe / clojure and just hit this little bump.

kennytilton16:06:16

On click each option dispatches a [:job-sort-set <myvalue>] event.

ScArcher16:06:20

I have a lot of other things bound and working, but this is the first radio button.

kennytilton16:06:17

I am new as well, I should warn you. But I have knocked off a fairly elaborate 1100LOC web app and got a bunch of things working along the way.

v3ga03:06:08

Hmm is your apps code public by chance?

ScArcher16:06:59

Right now i feel like my “components” are way too big. I should spend some time making them smaller. I’m also not confident on how they should be put together.

ScArcher16:06:08

On the flip side it’s working rest.

kennytilton16:06:27

Radio buttons might have a different event, such as onchange. Just keep that in mind.

kennytilton16:06:58

I think components should be as simple as possible, but no simpler. 🙂

kennytilton16:06:39

If it ain’t reusable, I do not break it out — unless there is just too much code to stare at at once. 🙂

ScArcher16:06:10

It feels strange to me doing all the the html in Clojurescript.

ScArcher16:06:38

Right now each component is a “section” on the page.

kennytilton16:06:54

Heh-heh, we have to “let go” when the paradigm shifts, eh?

ScArcher16:06:15

How do you handle HTML attributes that don’t have a value?

ScArcher16:06:20

Like “checked”

jeaye16:06:33

Haven't tried it yet, since we're on React Native, but http://pagedraw.io promises auto-generated React components from the WYSIWYG responsive designer. Given that 29% of our client code is in view namespaces, that'd be a huge win.

jeaye16:06:56

It'd also allow faster iteration from your designer into your app, I'd guess. Probably more relevant in #reagent, but I was reminded by the "writing HTML in CLJS" remark.

kennytilton17:06:46

I just got away with false on hidden. Which does not work in HTML, of course, but methinks any decent HTML wrapper fixes that. Or try nil/null depending on your language.

ScArcher18:06:13

Ok another question. If i start figwheel (lein figwheel dev) and i look at my db (println helpdesk.db/default-db) should I see what values are set in that DB in the browser I’m using?

Hukka18:06:06

If you look at your db, but that doesn't look like path to the db

Hukka18:06:24

The atom is at re-frame.db/app-db

Hukka18:06:46

Are you perhaps mixing it with some default values you use to initialize the db?

ScArcher18:06:41

That’s very possible. I’m new to all of this. Using this simple project to learn.

ScArcher18:06:18

My db.cljs just has a (def default-db {:mystuff “myvalues”}

ScArcher18:06:27

It just hold a map that is my DB, nothing more.

Hukka18:06:30

Well, that's just a map

Hukka18:06:36

It's not the re-frame db

Hukka18:06:48

Are you using a template of some kind?

ScArcher18:06:13

I did use a template to create the project, but I don’t recall which one.

Hukka18:06:47

Well... it's pretty difficult to give more specific advice with this background...

ScArcher18:06:12

It looks like

(def default-db           ;; what gets put into app-db by default.
  {:todos   (sorted-map)  ;; an empty list of todos. Use the (int) :id as the key
   :showing :all})        ;; show all todos
is what they define there.

ScArcher18:06:25

I may be missing something else.

Hukka18:06:47

So that says that when the db is getting initialized, load the values from that map

Hukka18:06:17

And as the comments mention, even that initialization isn't run automagically, but it's explicitly triggered at https://github.com/Day8/re-frame/blob/228d80a858e3751d322cceca9bed4ee61302ffae/examples/todomvc/src/todomvc/core.cljs#L24

Hukka18:06:29

Your default-db is immutable; it never changes

ScArcher18:06:03

So the database is stored in html5 local storage in this example?

ScArcher18:06:06

The one that changes?

ScArcher18:06:05

I really only want an in-memory db, not stored anywhere for this.

ScArcher18:06:31

Am I thinking about this wrong?

kennytilton19:06:13

Default DB is your starting DB. And in the land of Clojure, it will never be mutated. All “updates” to db make a new copy of the current map and put that make in db.

kennytilton19:06:58

As @tomi.hukkalainen_slac said, check out the app-db atom. If you want to inspect it. Me, I just look at the db param in event-db or (:db cfx) in event-fx to see what is the current map value as I debug.

kennytilton19:06:25

Back to my sort example, the setter event looks like this

(rfr/reg-event-db :job-sort-set
  (fn [db [_ new-sort]]
    (assoc db :job-sort new-sort)))

kennytilton19:06:43

assoc makes a new map. And for debugging, I can just println anything I want from db.

kennytilton19:06:55

The re-frame plumbing takes care of jamming my new map back into the app-db atom.

kennytilton19:06:40

^^^ “plumbing” is an interceptor helpfully provided by re-frame to make the magic happen (but magic can be tough on us noobs because we cannot see the moving parts).

ScArcher19:06:06

@hiskennyness I found what I was doing wrong. I was doing what you said, but the "db" parameter was wrong in my reg-event-db functions.

ScArcher19:06:18

which is why it wasn't updating properly.

ScArcher19:06:27

I also understand how the default-db is just the starting point.

👍 4
ScArcher19:06:32

Thank you for the help!

lwhorton22:06:30

any chance of cutting a new release for 0.0.11 of https://github.com/Day8/re-frame-async-flow-fx ?