Fork me on GitHub
#keechma
<
2018-01-10
>
sooheon08:01:22

@mihaelkonjevic Is there a reason why the params-fn in a pipeline-controller/constructor, for example, must return nil to turn off? I expected it to also turn off for false. Did you run into some problems?

sooheon08:01:39

Not counting false as a false-y value is different behavior from other predicates in clojure, and it forces code like (when (predicate? route-params) true) rather than just (predicate? route-params)

mihaelkonjevic08:01:54

@sooheon my reasoning was that false is still a value, while nil is absence of one. It’s a pretty arbitrary decision

sooheon09:01:21

are you envisioning cases where you encode something like ?paginate=false in the route?

mihaelkonjevic09:01:06

Not really, but I also don’t m ow what lies in the future :) . Nil vs value seemed like a good distinction because nil symbolizes absence of a controller and any value a presence of one

sooheon09:01:37

really loving keechma btw, I’m learning a lot.

sooheon09:01:44

thanks for putting this out there

mihaelkonjevic09:01:40

Thank you. If you need any help please reach out. There’s a lot of things in there that I wasn’t able to document properly yet, so I try to answer any questions as they come up

sooheon09:01:58

@mihaelkonjevic in the dataloader map, :params takes three args: prev, route, and deps. what are prev and deps?

sooheon09:01:48

does prev return the existing value (if any) at :target?

mihaelkonjevic09:01:53

Prev returns result of the previous loading. It will have meta and data keys. This allows you to use the previous version to check if you need to do a reload. It’s also useful if you’re doing something like infinite loading where you just append to the previously loaded data

mihaelkonjevic09:01:01

Deps returns values of data sources that the current data source depends on

sooheon09:01:34

Cool, so if I don’t explicitly take prev into account, and I keep reloading the page on the same route, it will keep clearing and re-fetching the data?

mihaelkonjevic09:01:22

Data will be refetched only if the params db returns value that is different from the previous one

mihaelkonjevic09:01:23

It works like controller’s params fn but nil doesn’t have a special meaning. Even if you return nil, loader fn will be called

mihaelkonjevic09:01:00

This data source depends on jwt data source so it can sign the requests

mihaelkonjevic09:01:34

Deps allow you to define a graph of data sources with dependencies, and dataloader will correctly invalidate and reload datasources whose deps changed too

sooheon09:01:45

so the reason for jwt-datasource having that :prev check -> ignore and no :params is because whether to load or not doesn’t depend on route, but on whether the jwt exists in local-storage or not?

mihaelkonjevic09:01:39

Yes and once it exists you don’t need to load it again. If the user logs out, you can remove jwt manually from a controller and then force a dataloader reload.

sooheon09:01:45

Got it. Also, if I tried to mock :loader to return just data like:

(map-loader
 (fn [req]
   (when (:params req)
     ;; TODO
     ;; (ajax/GET "/api/stats/total")
     (print "loading data...")
     [{:id 1 :clicks 100 :impressions 200}
      {:id 2 :clicks 300 :impressions 700}])))
but this doesn’t work. How do you test them?

mihaelkonjevic09:01:26

Hm, this looks like it should work

sooheon09:01:52

Where else do I need to hook up dataloaders other than app-definition?

mihaelkonjevic09:01:21

Do you have a dataloader controller running?

sooheon09:01:31

No, I guess that’s it.

sooheon09:01:40

I thought just defining the datasource was enough

sooheon09:01:29

is this it?

sooheon09:01:25

Thanks, it’s working :)