Fork me on GitHub
#keechma
<
2016-07-05
>
bocaj17:07:51

This seems like a bad pattern, but what if you change the url from the component using (ui/url this {:query "where is waldo"})? that's more coupled than sending a command, right?

mihaelkonjevic17:07:00

I don’t really think it’s a bad patter. URL is always there, and you can control how the URL is formatted from the outside. You just persist part of the state in the URL (so you can recreate some stuff on reload)

mihaelkonjevic17:07:24

actually URLs are the most important part in Keechma because they drive controllers, so use them freely 🙂

mihaelkonjevic17:07:47

the controllers are the one who assign the meaning to the URL data, so it’s already somewhat decoupled

bocaj17:07:02

I see. So it's possible and "OK", but is this how you designed the system to be used? Or, do use commands from components as a rule of thumb?

mihaelkonjevic17:07:35

so, here’s how I see it: URL change is “tectonic” change for the state. It might cause a lot of stuff happening at once. That’s why controllers react to urls and are getting started or stopped. Commands are for gradual changes between the tectonic changes, that’s why started controllers can listen to commands. But controllers are started only when they care about the data in the URL

mihaelkonjevic17:07:54

so yeah, it’s designed to work like that

bocaj17:07:57

Ok. So when you change a url and every controller listens for the url change, then a lot of stuff, potentially, will happen on url change.

bocaj17:07:45

But, if you're sending commands off to a topic, then you can very clearly see what is happening. Fewer effects.

mihaelkonjevic17:07:03

these two diagrams show difference between the route change and command

mihaelkonjevic17:07:39

it really depends on you what stuff you put in the URL, but my philosophy is to put in everything I need to recreate the app state on reload

mihaelkonjevic17:07:59

that way you can reason about your app as if every route change is basically page reload.

bocaj17:07:03

Yea, I like that principle.

bocaj17:07:36

So, the way I see it, using a command, it's a good idea for the controller to update the url. For example, /page?q=a+query

bocaj17:07:56

Or, for the component to change the url, and the controllers handle that change.

bocaj17:07:48

Hmm, but if the controller is redirecting to a url anyways, it's a design decision regarding which option to take

mihaelkonjevic17:07:26

I would use controller to change the url only if there is some preprocessing involved

mihaelkonjevic17:07:38

for instance if you have a live search, and you want to wait until user is not typing for 200ms

mihaelkonjevic17:07:50

otherwise I’d just change the url from the component

bocaj17:07:15

That is a perfect example. Just what I'm doing right now.