keechma

Keechma stack. Mention @U050986L9 or @U2J1PHYNM if you have any questions
sooheon 2018-01-10T08:51:22.000259Z

@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?

sooheon 2018-01-10T08:53:39.000145Z

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)

mihaelkonjevic 2018-01-10T08:58:54.000289Z

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

sooheon 2018-01-10T09:00:21.000258Z

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

mihaelkonjevic 2018-01-10T09:03:06.000273Z

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

sooheon 2018-01-10T09:03:28.000245Z

got it :)

sooheon 2018-01-10T09:03:37.000004Z

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

sooheon 2018-01-10T09:03:44.000143Z

thanks for putting this out there

mihaelkonjevic 2018-01-10T09:04:40.000060Z

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

👌 1
sooheon 2018-01-10T09:36:58.000110Z

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

sooheon 2018-01-10T09:38:48.000509Z

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

mihaelkonjevic 2018-01-10T09:41:53.000326Z

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

mihaelkonjevic 2018-01-10T09:43:01.000078Z

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

sooheon 2018-01-10T09:43:34.000008Z

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?

mihaelkonjevic 2018-01-10T09:44:22.000228Z

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

mihaelkonjevic 2018-01-10T09:45:23.000170Z

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

mihaelkonjevic 2018-01-10T09:46:00.000294Z

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

mihaelkonjevic 2018-01-10T09:47:34.000528Z

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

sooheon 2018-01-10T09:48:45.000217Z

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?

mihaelkonjevic 2018-01-10T09:51:39.000034Z

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.

sooheon 2018-01-10T09:52:45.000077Z

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?

mihaelkonjevic 2018-01-10T09:54:26.000063Z

Hm, this looks like it should work

sooheon 2018-01-10T09:54:52.000104Z

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

mihaelkonjevic 2018-01-10T09:55:21.000072Z

Do you have a dataloader controller running?

sooheon 2018-01-10T09:55:31.000512Z

No, I guess that’s it.

sooheon 2018-01-10T09:55:40.000325Z

I thought just defining the datasource was enough

sooheon 2018-01-10T09:56:29.000588Z

is this it?

sooheon 2018-01-10T09:59:25.000221Z

Thanks, it’s working :)

🎉 1