Fork me on GitHub
#re-frame
<
2017-12-19
>
mikethompson00:12:01

@jarrodctaylor I'd suggest you read Eric's article ... https://purelyfunctional.tv/guide/database-structure-in-re-frame/ Look in particular at the "Naming Recommendations" section. We want our views to dispatch events which capture user "intent".

mikethompson00:12:51

We don't want logic in views

mikethompson00:12:14

Your first attempt put logic into the view, and tried to use dispatch as a kind of "function call"

mikethompson00:12:34

mikerod correctly pointed you towards an alternative version where the view simply dispatches an event which captures the user's intent and then it is up the event handler to know how that intent should be implemented (never the view)

mikerod01:12:14

@mikethompson yeah I wasn’t sure on the name either. The situation was generic so i didn’t know of a semantic “intent”. I was almost going to mention the naming thing too

mikerod01:12:37

I am myself trying to improve my naming of these things.

andrea.crotti14:12:01

any nice way to use namespaced keywords but still have handlers that can be shared across different namespaces?

andrea.crotti14:12:37

we are using namespaced keywords now, which is nice, but sometimes it's quite a pain to try to share handlers across different pages

manutter5114:12:39

I just recently learned the trick where you (require '[some.big.long.hard-to-type.namespace :as sblhn]) and then you can use ::sblhn/my-keyword instead of typing out the whole thing.

manutter5114:12:03

Does that help?

mikerod14:12:41

@manutter51 I was goign to say the same thing 😛

mikerod14:12:54

However, I have also used namespaced keywords that aren’t relative to an actual ns

mikerod14:12:24

:not-a-clj-ns/foo

mikerod14:12:59

Just as another idea that is

manutter5114:12:04

Yeah, I have some like that too, I just consider those to be "keywords with built-in documentation". More to type, but worth the effort.

andrea.crotti15:12:01

yeah I knew that trick

andrea.crotti15:12:17

but it doesn't really help in a way since each page has a different db for example

andrea.crotti15:12:47

and if I want to use the same handler function in two pages, I can't use do it directly with namespaced keywords

andrea.crotti15:12:02

could maybe pass the caller namespace into the function maybe, but it's not really great

manutter5115:12:29

Maybe you need to refactor your namespaces, and/or use namespaced keywords that don’t correspond to an actual ns?

manutter5116:12:49

Like if you have something in a foo namespace and you want to share it with a bar namespace, pull it out of foo into like common or util or something.