@@ -71,8 +71,8 @@ order of plugins. *How?* Glad you asked, check out
71
71
[ ` avvio ` ] ( https://github.com/mcollina/avvio ) ! Fastify starts loading the plugin
72
72
__ after__ ` .listen() ` , ` .inject() ` or ` .ready() ` are called.
73
73
74
- Inside a plugin you can do whatever you want, register routes, utilities (we
75
- will see this in a moment) and do nested registers, just remember to call ` done `
74
+ Inside a plugin you can do whatever you want, register routes and utilities (we
75
+ will see this in a moment), and do nested registers, just remember to call ` done `
76
76
when everything is set up!
77
77
``` js
78
78
module .exports = function (fastify , options , done ) {
@@ -117,7 +117,7 @@ Now you can access your utility just by calling `fastify.util` whenever you need
117
117
it - even inside your test.
118
118
119
119
And here starts the magic; do you remember how just now we were talking about
120
- encapsulation? Well, using ` register ` and ` decorate ` in conjunction enable
120
+ encapsulation? Well, using ` register ` and ` decorate ` in conjunction enables
121
121
exactly that, let me show you an example to clarify this:
122
122
``` js
123
123
fastify .register ((instance , opts , done ) => {
@@ -137,7 +137,7 @@ Inside the second register call `instance.util` will throw an error because
137
137
` util ` exists only inside the first register context.
138
138
139
139
Let's step back for a moment and dig deeper into this: every time you use the
140
- ` register ` API, a new context is created which avoids the negative situations
140
+ ` register ` API, a new context is created that avoids the negative situations
141
141
mentioned above.
142
142
143
143
Do note that encapsulation applies to the ancestors and siblings, but not the
@@ -202,7 +202,7 @@ a utility that also needs access to the `request` and `reply` instance,
202
202
a function that is defined using the ` function ` keyword is needed instead
203
203
of an * arrow function expression* .
204
204
205
- In the same way you can do this for the ` request ` object:
205
+ You can do the same for the ` request ` object:
206
206
``` js
207
207
fastify .decorate (' getHeader' , (req , header ) => {
208
208
return req .headers [header]
@@ -395,7 +395,7 @@ As we mentioned earlier, Fastify starts loading its plugins __after__
395
395
have been declared. This means that, even though the plugin may inject variables
396
396
to the external Fastify instance via [ ` decorate ` ] ( ../Reference/Decorators.md ) ,
397
397
the decorated variables will not be accessible before calling ` .listen() ` ,
398
- ` .inject() ` or ` .ready() ` .
398
+ ` .inject() ` , or ` .ready() ` .
399
399
400
400
In case you rely on a variable injected by a preceding plugin and want to pass
401
401
that in the ` options ` argument of ` register ` , you can do so by using a function
0 commit comments