Skip to content

Commit 2879f5c

Browse files
authored
Merge pull request #45 from podium-lib/more-restructuring
refactor: collect guides in one category and fix link warnings
2 parents 1a4eafc + 4ad4090 commit 2879f5c

16 files changed

+232
-273
lines changed

blog/2019-08-19-version-4.2.0.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ will translate into the following HTML element:
4646
Please see the following documentation for the options the different methods
4747
can now take:
4848

49-
* @podium/podlet [`.css()`](/docs/api/podlet#cssoptions-options) method
50-
* @podium/podlet [`.js()`](/docs/api/podlet#jsoptions-options) method
51-
* @podium/layout [`.css()`](/docs/api/layout#cssoptions-options) method
52-
* @podium/layout [`.js()`](/docs/api/layout#jsoptions-options) method
49+
- @podium/podlet [`.css()`](/docs/api/podlet#cssoptionsoptions) method
50+
- @podium/podlet [`.js()`](/docs/api/podlet#jsoptionsoptions) method
51+
- @podium/layout [`.css()`](/docs/api/layout#cssoptionsoptions) method
52+
- @podium/layout [`.js()`](/docs/api/layout#jsoptionsoptions) method
5353

5454
For further information on how assets are handled in general, please see the
5555
[asset section](/docs/api/assets).

docs/api/layout.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,15 +1705,15 @@ layout.client.fooBar.fetch();
17051705

17061706
#### options (required)
17071707

1708-
| option | type | default | required | details |
1709-
| ---------- | --------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1710-
| uri | `string` | | ✓ | Uri to the manifest of a podlet |
1711-
| name | `string` | | ✓ | Name of the component. This is used to reference the component in your application, and does not have to match the name of the component itself |
1712-
| retries | `number` | `4` | | The number of times the client should retry to settle a version number conflict before terminating. Overrides the `retries` option in the layout constructor |
1713-
| timeout | `number` | `1000` | | Defines how long, in milliseconds, a request should wait before the connection is terminated. Overrides the `timeout` option in the layout constructor |
1714-
| throwable | `boolean` | `false` | | Defines whether an error should be thrown if a failure occurs during the process of fetching a podlet. [See handling podlet unavailability](../layout/unavailable_podlets.md). |
1715-
| resolveJs | `boolean` | `false` | | Defines whether to resolve relative URIs to absolute URIs for JavaScript assets |
1716-
| resolveCss | `boolean` | `false` | | Defines whether to resolve relative URIs to absolute URIs for CSS assets |
1708+
| option | type | default | required | details |
1709+
| ---------- | --------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1710+
| uri | `string` | | ✓ | Uri to the manifest of a podlet |
1711+
| name | `string` | | ✓ | Name of the component. This is used to reference the component in your application, and does not have to match the name of the component itself |
1712+
| retries | `number` | `4` | | The number of times the client should retry to settle a version number conflict before terminating. Overrides the `retries` option in the layout constructor |
1713+
| timeout | `number` | `1000` | | Defines how long, in milliseconds, a request should wait before the connection is terminated. Overrides the `timeout` option in the layout constructor |
1714+
| throwable | `boolean` | `false` | | Defines whether an error should be thrown if a failure occurs during the process of fetching a podlet. [See Fallbacks](/docs/guides/fallbacks). |
1715+
| resolveJs | `boolean` | `false` | | Defines whether to resolve relative URIs to absolute URIs for JavaScript assets |
1716+
| resolveCss | `boolean` | `false` | | Defines whether to resolve relative URIs to absolute URIs for CSS assets |
17171717

17181718
### .client.refreshManifests()
17191719

@@ -1736,8 +1736,7 @@ await layout.client.refreshManifests();
17361736

17371737
### .client.state
17381738

1739-
What state the client is in. See the section
1740-
"[Podlet update life cycle](#podlet-update-life-cycle)" for more information.
1739+
What state the client is in.
17411740

17421741
The value will be one of the following values:
17431742

@@ -1753,8 +1752,7 @@ The Client instance emits the following events:
17531752

17541753
#### state
17551754

1756-
When there is a change in state. See the section
1757-
"[Podlet update life cycle](#podlet-update-life-cycle)" for more information.
1755+
When there is a change in state.
17581756

17591757
```js
17601758
layout.client.on("state", (state) => {

docs/api/podlet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ The prefix will be ignored if value is an absolute URL.
17111711

17121712
Method for defining proxy targets to be mounted in a layout server. For a
17131713
detailed overview of how proxying works, please see the
1714-
[proxying guide](podlet/proxying.md) for further details.
1714+
[proxying guide](/docs/guides/proxying) for further details.
17151715

17161716
When a podlet is put in development mode (`development` is set to `true` in the constructor) these proxy endpoints will also be mounted in the podlet for ease of development and you will then have the same proxy endpoints available in development as you do when working with a layout.
17171717

docs/introduction/assets.md renamed to docs/guides/assets.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,3 @@ Using the [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_comp
124124
With `podlet.css()` the end result is a `<link />` tag in the HTML document's `<head />`. If your podlet's content renders inside a shadow DOM that CSS won't be able to reach the podlet.
125125

126126
With a declarative shadow DOM you have to include your own `<link />` to the CSS from inside the shadow DOM.
127-
128-
## Next steps
129-
130-
Next you might want to familiarise yourself with the Podium context.

docs/podlet/podlet_to_podlet_communication.md renamed to docs/guides/client-side-communication.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
id: podlet_to_podlet_communication
3-
title: Podlet to podlet communication in the browser
2+
title: Client-side communication in a Podium app
43
---
54

65
Podium provides a client side library called [@podium/browser] that includes a [MessageBus](/docs/api/browser#messagebus). The message bus simplifies passing data between different podlets' client-side JavaScript.

docs/introduction/context.md renamed to docs/guides/context.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ podlet.defaults({
125125
});
126126
```
127127

128-
## Next steps
129-
130-
Next you may want to look at the different guides for podlets and layouts which cover some common scenarios.
131-
132128
[bcp47]: https://tools.ietf.org/html/bcp47
133129
[kebab case]: https://en.wikipedia.org/wiki/Kebab_case
134130
[camel case]: https://en.wikipedia.org/wiki/Camel_case

docs/podlet/fallbacks.md renamed to docs/guides/fallbacks.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ id: fallbacks
33
title: Fallbacks
44
---
55

6-
What happens if a podlet server is down? Unresponsive? Responding too slowly? By default Podium will simply render an empty string in its place. You might, however, want to have some measure of control over what gets shown. Enter fallbacks.
6+
What happens to a layout if a podlet is down, unresponsive, or slow? By default the layout will render an empty string in its place. However, you might want to have control what gets shown, such as a simplified static version of a complex dynamic podlet. Fallbacks let you do this.
77

88
## How do fallbacks work?
99

1010
On the first request to a podlet a layout will read the podlet’s [manifest](/docs/api/manifest). The manifest includes the location of the fallback. The layout then makes a request to the fallback route and caches the response.
1111

1212
Later, if the podlet server cannot be reached for any reason, or the request returns a non 200 response, the layout will use the podlet’s cached fallback content instead.
1313

14-
Note that the podlet’s assets will still be served, so the fallback can depend on both JS and CSS being present once it’s rendered. This assumes the assets are hosted on a server [separate from the podlet](/docs/introduction/assets#use-a-cdn).
14+
Note that the podlet’s assets will still be served, so the fallback can depend on both JS and CSS being present once it’s rendered. This assumes the assets are hosted on a server [separate from the podlet](/docs/guides/assets#use-a-cdn).
1515

1616
## Defining a fallback route
1717

@@ -55,3 +55,35 @@ const podlet = new Podlet(/*...*/);
5555

5656
podlet.fallback("https://www.example.com/my-fallback");
5757
```
58+
59+
## Throwable podlets
60+
61+
By default a layout will substitute a fallback (or empty string) for a podlet's content whenever the podlet either fails to respond with a 2xx status code or the podlet fails to respond within 1000 milliseconds.
62+
63+
In some cases it may make no sense to show a page at all if some of its content is not available. You may prefer to show an error page rather than fallback content or an empty string. This is especially true for dynamic content that is the main focus of a page. If all you can show is a header and footer, it might be better to show an error page explaining the situation to the user.
64+
65+
In order to facilitate this, it is possible to set a podlet as `throwable` when it is registered.
66+
67+
```js
68+
const gettingStarted = layout.client.register({
69+
throwable: true,
70+
});
71+
```
72+
73+
When the layout fetch the podlet, if that podlet is not available, then the fetch will reject with an error that you can then handle as you see fit.
74+
75+
Error objects are instances of [Boom](https://www.npmjs.com/package/@hapi/boom) errors and are decorated with the HTTP status code from the podlet response.
76+
77+
```js
78+
app.get(layout.pathname(), (req, res, next) => {
79+
try {
80+
const content = await gettingStarted.fetch(res.locals.podium);
81+
} catch(err) {
82+
// you might respond to the error here
83+
// res.status(err.statusCode).end();
84+
85+
// or pass the error on to be handled in error handling middleware
86+
next(err);
87+
}
88+
});
89+
```

0 commit comments

Comments
 (0)