From 8e380f14eb5eaa23f7af2b670504e62c9763f6d8 Mon Sep 17 00:00:00 2001 From: Automatic build Date: Thu, 14 Sep 2017 15:09:01 +0000 Subject: [PATCH] Build book from commit aff2229151a9bdf3525653faefdeb9c2dc6aef1a --- compiling_middleware.html | 6 +++--- configuring_routers.html | 2 +- index.html | 2 +- parameter_coercion.html | 2 +- ring.html | 2 +- routing/route_conflicts.html | 2 +- routing/route_metadata.html | 4 ++-- routing/route_syntax.html | 2 +- routing/routers.html | 2 +- validating.html | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiling_middleware.html b/compiling_middleware.html index 4db286a2..21b56fac 100644 --- a/compiling_middleware.html +++ b/compiling_middleware.html @@ -323,9 +323,9 @@

Compiling Middleware

-

The meta-data extensions are a easy way to extend the system. Routes meta-data can be transformed into any shape (records, functions etc.) in route compilation, enabling fast access at request-time.

+

The meta-data extensions are a easy way to extend the system. Routes meta-data can be transformed into any shape (records, functions etc.) in route compilation, enabling fast access at request-time.

Still, we can do better. As we know the exact route that interceptor/middleware is linked to, we can pass the (compiled) route information into the interceptor/middleware at creation-time. It can extract and transform relevant data just for it and pass it into the actual request-handler via a closure - yielding faster runtime processing.

-

To do this we use middleware records :gen hook instead of the normal :wrap. :gen expects a function of route-meta router-opts => wrap. Middleware can also return nil, which effective unmounts the middleware. Why mount a wrap-enforce-roles middleware for a route if there are no roles required for it?

+

To do this we use middleware records :gen hook instead of the normal :wrap. :gen expects a function of route-meta router-opts => wrap. Middleware can also return nil, which effective unmounts the middleware. Why mount a wrap-enforce-roles middleware for a route if there are no roles required for it?

To demonstrate the two approaches, below are response coercion middleware written as normal ring middleware function and as middleware record with :gen. These are the actual codes are from reitit.coercion:

Naive

@@ -408,7 +408,7 @@ diff --git a/routing/route_syntax.html b/routing/route_syntax.html index fbcbd4e5..caf59862 100644 --- a/routing/route_syntax.html +++ b/routing/route_syntax.html @@ -388,7 +388,7 @@ diff --git a/routing/routers.html b/routing/routers.html index 5231c52a..d81044c0 100644 --- a/routing/routers.html +++ b/routing/routers.html @@ -424,7 +424,7 @@ diff --git a/validating.html b/validating.html index 46fddad6..396714db 100644 --- a/validating.html +++ b/validating.html @@ -451,7 +451,7 @@