Skip to content

Commit

Permalink
docs: various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Aug 5, 2023
1 parent e34cbd3 commit 792b544
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ variety of officially supported modules that extend it.
### Expressive

* Routes are pure functions that transform requests into responses
* Route functions receive a prepared request object with easily accessible
* Route functions accept a prepared request object with easily accessible
`body`, `path`, `query`, `cookies` and `headers` fields

### Minimal
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/guards.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Many web applications have some form of privilege separation, for instance
between guest and authenticated users. In Primate, excluding certain clients
from accessing routes is achieved with guards.

A guard is a function that, like all route functions, receives a `request`
A guard is a function that, like all route functions, accepts a `request`
object as its sole parameter. Guards are tasked with deciding whether to let
clients pass through, and they do so by returning exactly `true`. If the guard
returns anything else, including `undefined`, the route function won't execute.
Expand Down
39 changes: 18 additions & 21 deletions docs/guide/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ subscribers accept different types of parameters, depending on the hook.
**Precondition** configuration has been loaded and merged with defaults

The first hook to be called, directly after app start-up and loading the
configuration file. This hook is for modules to initialize state or load other
modules.
configuration file. This hook is for modules to load other modules.

```js caption=primate.config.js
export default {
Expand All @@ -87,7 +86,7 @@ export default {

!!!
Dependent modules loaded using `app.load` **are not** currently triggered
by `load` hook themselves. Also, unlike all other hooks, the `load` hook does
by `load` hook themselves. Also, unlike most other hooks, the `load` hook does
not accept a final `next` parameter.
!!!

Expand Down Expand Up @@ -119,6 +118,11 @@ export default {
};
```

!!!
Unlike most other hooks, the `init` hook does not accept a final `next`
parameter.
!!!

## register

**Executed** once
Expand All @@ -129,19 +133,14 @@ This hook allows modules to register a component file extension to be handled
by `view`.

```js caption=primate.config.js
/**
/* @param {string} name the component name, for example `clock.mustache`
/* @param {object} props any props passed to the component
/* @param {options} options any additional options passed to the component
*/
const mustacheHandler = (name, props, options) => {
// load the component file and render it into HTML using props
// load the component file using its name and render it into HTML with props
};

export default {
modules: [{
name: "register-hook-example-module",
// receives the app object augmented with a `register` function
// accepts the app object augmented with a `register` function
register(app, next) {
app.register("mustache", mustacheHandler);
return next(app);
Expand Down Expand Up @@ -180,7 +179,7 @@ it particularly useful for [frontend frameworks][frontend-frameworks] which use
their own domain-specific languages (React's `.jsx`, Vue's `.vue` (SFC),
Svelte's `.svelte` etc.) to be served through server-side rendering.

This hook receives the app as its first and the next subscriber as its second
This hook accepts the app as its first and the next subscriber as its second
parameter.

## publish
Expand All @@ -189,16 +188,14 @@ parameter.

**Precondition** none

This hook allows modules to publish client-side code and entry points to
memory. Primate loads and serves JavaScript/CSS files in the `static`
directory directly from memory, and this hook is particularly useful for
[frontend frameworks][frontend-frameworks], which might need to register their
own core scripts.
This hook allows modules to publish client-side code and entry points. It is
particularly useful for [frontend frameworks][frontend-frameworks], which may
need to register their own core scripts.

Publishing entry points allow bundler modules to effectively consolidate code
during the `bundle` hook.

This hook receives the app as its first and the next subscriber as its second
This hook accepts the app as its first and the next subscriber as its second
parameter.

## bundle
Expand All @@ -220,7 +217,7 @@ have been loaded into memory previously, either during the `publish` hook or by
Primate loading them from the `static` directory, into consolidated code. It is
particularly useful for bundler modules such as [esbuild](/modules/esbuild).

This hook receives the app as its first and the next subscriber as its second
This hook accepts the app as its first and the next subscriber as its second
parameter.

## serve
Expand All @@ -235,7 +232,7 @@ modules can add support for additional verbs aside from the official HTTP
verbs. For example, the [WebSocket](/modules/ws) module adds support for
a `ws` verb.

This hook receives the app, augmented with a `server` property, as its first
This hook accepts the app, augmented with a `server` property, as its first
and the next subscriber as its second parameter.

## handle
Expand Down Expand Up @@ -269,7 +266,7 @@ const augment = request => {
export default {
modules: [{
name: "handle-hook-example-module",
// receives the request object without the `path` property
// accepts the request object without the `path` property
handle(request, next) {
return next(augment(request));
},
Expand Down Expand Up @@ -302,7 +299,7 @@ const delegate = request => {
export default {
modules: [{
name: "route-hook-example-module",
// receives the request object without the `path` property
// accepts the request object without the `path` property
route(request, next) {
if (request.url.pathname.startsWith("/admin")) {
// delegate request to admin app
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/responses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Responses

Every route function represents an HTTP verb that receives a request and
returns a response.
Every route function represents an HTTP verb that accepts a request and returns
a response.

Depending on the type of content returned from a route, Primate will guess a
content type for you automatically. This applies to strings, objects, readable
Expand Down
7 changes: 4 additions & 3 deletions docs/guide/use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Content-Type: application/json
{"title":"Comment title","text":"Comment text"}
```

Then Primate will respond in plain text as follows.
Then, given the above route definition, Primate will respond in plain text as
follows.

```text
You've sent a PUT request with the following data:
Expand Down Expand Up @@ -107,9 +108,9 @@ login, sessions). The Primate website uses Priss itself.
[view-handler]: /guide/responses#view
[quick-start]: /guide/getting-started#quick-start
[frameworks]: /modules/frameworks
[stores]: /modules/stores
[stores]: /modules/store
[bundling]: /modules/esbuild
[sessions]: /modules/sessions
[sessions]: /modules/session
[extending-primate]: /guide/extending-primate
[official-modules]: /modules/official
[priss]: https://github.com/primatejs/priss

0 comments on commit 792b544

Please sign in to comment.