Fork me on GitHub
#reitit
<
2018-11-21
>
Heikki Hämäläinen07:11:31

0.2.8 Reitit For some reason Swagger generation fails in situation when response body is vector containing data-spec. Generating data spec with ds/spec works fine so syntax should be legal. Is this bug or a feature?

ikitommi09:11:47

@heikki.hamalainen it seems that the reitit.coercion.spec/IntoSpec is missing a mapping for vectors/sequences. PR welcome.

Heikki Hämäläinen10:11:28

Great 🙂 maybe I can make this.

urzds13:11:57

In the [initial blog post](https://www.metosin.fi/blog/reitit/) you mentioned a re-frame helper module. Where can I find this?

ikitommi13:11:14

@urzds re-frame helpers haven't been published, but the controllers are part of reitit-frontend, here's a sample app (with reagent): https://github.com/metosin/reitit/blob/master/examples/frontend-controllers/src/frontend/core.cljs

urzds13:11:50

@ikitommi :start and :stop are functions that will be called when browsing to a route / page and when leaving it again?

ikitommi13:11:12

yes, the docs are kinda missing, but all the source code for controllers is in here: https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/controllers.cljs

urzds13:11:22

So that's where I would put the re-frame/dispatch in order to trigger the re-frame dominoes to switch the page?

ikitommi13:11:54

there is also kee-frame, which uses reitit, but with it’s own global controller definitions.

ikitommi13:11:47

@juhoteperi could explain it better, but the router takes care of page changes, controllers are for preparing data for the page, e.g.

[["/users" {:controllers [load-users]}
  ["/:id" {:controllers [load-user-by-id]}]]
 ["/pastas" {:controllers [load-pastas]}]]
, navigating to /users will ensure that load-users :start gets called. going to /users/1 will not reload that, but would call :start of load-user-by-id. Going back to /users will cause :load-user-by-id to :stop. Moving to /pastas from users/1 will :stop both user-controllers and start the load-pastas.

ikitommi13:11:19

frontend routing is naturally stateful, and controllers are a good fit there.

ikitommi13:11:11

I think the re-frame helpers could be put into an example, not much code there either.

juhoteperi13:11:23

The callback to router start! should be used to call dispatch to change page

juhoteperi13:11:10

There is no reason to write any re-frame helpers

urzds14:11:12

@juhoteperi Could you please explain that some more? Which callback? And dispatch means re-frame/dispatch and "change page" means whatever mechanism my application uses to change the page? (e.g. :active-page in the :db?)

ikitommi14:11:43

@heikki.hamalainen the vector data-spec fix out in [metosin/reitit "0.2.9"], thanks!

🚀 4
Heikki Hämäläinen14:11:13

There seems to be also in :response handling same kind of presupposition that response is always map -> doesnt allow for example {200 [int?] It seems that in this situation the problem lies in https://github.com/metosin/reitit/blob/master/modules/reitit-spec/src/reitit/coercion/spec.cljc create function which I try to fix this next 🙂

ikitommi15:11:04

@heikki.hamalainen isn't that {200 {:body [int?]}}

Heikki Hämäläinen15:11:35

@ikitommi Uups, stupid me. - i didnt have that body key there Forget everything 🙂 Workds fine. Too late - have to go to home.