Skip to content

Commit 8e8e334

Browse files
committed
chore: update docs with latest changes
1 parent 87b80c4 commit 8e8e334

File tree

3 files changed

+95
-80
lines changed

3 files changed

+95
-80
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# `const` to `function` manager providers
2+
3+
## TL;DR
4+
5+
Individual metadata managers `const`-based providers like `OPEN_GRAPH_DESCRIPTION_METADATA_PROVIDER` weren't tree shakeable by design . So they are replaced by `function`-based provider APIs. Like `provideOpenGraphDescription`
6+
7+
Update from `1.0.0-beta.34` to `1.0.0-beta.35` using `ng update` to replace old ones with new ones automatically for your project. See [migration](#migration) for more info about running automatic migrations or migrating manually.
8+
9+
## Summary
10+
11+
| Key | Value |
12+
| :----------------------------- | :------------------------------------ |
13+
| Category of change | 👎 **Deprecation** |
14+
| Automatic migration schematics | [✅ Yes. Via `ng update`](#automatic) |
15+
| Introduced in version | `1.0.0-beta.35` |
16+
17+
## Description
18+
19+
### Issue
20+
21+
[GitHub issue]: https://github.com/davidlj95/ngx/issues/960
22+
23+
[**🎟️ Detailed GitHub issue**][GitHub issue]
24+
25+
The library allows to select individual metadata managers to use. For instance, just Open Graph title and description. This way you can use only the code you need, hence reducing your app's bundle size. Take a look at the [custom metadata providers selection guide](custom-metadata-providers-selection.md) for more information.
26+
27+
Until `1.0.0-beta.35`, individual metadata manager providers were `const`s that you could add to your `providers` to use them. With this naming convention:
28+
29+
- `OPEN_GRAPH_TITLE_METADATA_PROVIDER`
30+
- `STANDARD_TITLE_METADATA_PROVIDER`
31+
- `TWITTER_CARD_TITLE_METADATA_PROVIDER`
32+
33+
However, the way these tokens are created means they aren't tree-shakeable (see [GitHub issue] for more details about why).
34+
Therefore, defeating its purpose of reducing the bundle size by just using the ones you need. All providers from a [built-in metadata module] would be included in the bundle size even if just one is used.
35+
36+
### Options
37+
38+
If using [pure annotations](https://terser.org/docs/miscellaneous/#annotations) , `const`-based providers can be tree-shaken. But it's easy to forget to add them hence resulting in non-tree shakeable providers. Some tests could be added to enforce that, but it's more infra to maintain.
39+
40+
An alternative is to use functions instead of `const`s for individual metadata manager providers. Functions are tree-shaken by default if unused. And they provide flexibility to customize the behaviour of a metadata manager provider by adding arguments to it. So allows extensibility in the long run. The trade-off is some few extra bytes[^1].
41+
42+
### Changes
43+
44+
New function-based individual metadata manager providers use this naming convention:
45+
46+
- `provideOpenGraphTitle()`
47+
- `provideStandardTitle()`
48+
- `provideTwitterCardTitle()`
49+
50+
The only exception is `JSON_LD_METADATA_PROVIDER`. Instead of a new `function`-based alternative, it is replaced by [`provideNgxMetaJsonLd`](ngx-meta.providengxmetajsonld.md). The JSON-LD module provider API. Given they actually do the same (indeed the latter calls the former under the hood). So no need to maintain two functions with same purpose.
51+
52+
## Migration
53+
54+
In order to migrate from old `const`-based individual metadata manager providers into new, `function`-based individual metadata manager providers, you can:
55+
56+
### Automatic
57+
58+
Use the automatic migration [schematic](https://angular.dev/tools/cli/schematics) by upgrading to that version with `ng update` command:
59+
60+
```shell
61+
ng update @davidlj95/ngx-meta@latest
62+
```
63+
64+
The schematic will look for old managers and replace them by new ones. It will fix imports too. If you have already upgraded, you can also run:
65+
66+
```shell
67+
ng update @davidlj95/ngx-meta \
68+
--from=1.0.0-beta.35 \
69+
--migrate-only
70+
# or also
71+
ng update @davidlj95/ngx-meta \
72+
--name=const-to-function-manager-providers
73+
```
74+
75+
## Manual
76+
77+
Look for `const`-based individual metadata manager providers in your project and replace them with the new `function`-based providers. They are imported from the same entrypoint. They can be identified by their suffix: `_METADATA_PROVIDER`.
78+
79+
Some examples:
80+
81+
| Old usage | New usage |
82+
| -------------------------------------: | :------------------------ |
83+
| `OPEN_GRAPH_TITLE_METADATA_PROVIDER` | `provideOpenGraphTitle` |
84+
| `STANDARD_TITLE_METADATA_PROVIDER` | `provideStandardTitle` |
85+
| `TWITTER_CARD_TITLE_METADATA_PROVIDER` | `provideTwitterCardTitle` |
86+
| `JSON_LD_METADATA_PROVIDER` | `provideNgxMetaJsonLd` |
87+
88+
The only change that doesn't follow the naming pattern is `JSON_LD_METADATA_PROVIDER` for the reasons stated in the [changes](#changes) section.
89+
90+
You can find a full list [in the schematics testing support file](https://github.com/davidlj95/ngx/blob/ngx-meta-v1.0.0-beta.32/projects/ngx-meta/schematics/migrations/tree-shakeable-manager-providers/testing/replacements.ts)
91+
92+
Finally, the [custom metadata providers selection guide](custom-metadata-providers-selection.md) has been updated with new usages. But you can check [an older version](https://github.com/davidlj95/ngx/blob/ngx-meta-v1.0.0-beta.31/projects/ngx-meta/docs/content/guides/custom-metadata-providers-selection.md) if you need to.
93+
94+
[^1]: See the [PR introducing changes](https://github.com/davidlj95/ngx/pull/1004) for details about the extra bundle size increase.

projects/ngx-meta/docs/content/migrations/tree-shakeable-manager-providers.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

projects/ngx-meta/docs/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ nav:
3939
- API Reference: api/ngx-meta.md
4040
- changelog.md
4141
- Migrations:
42-
- migrations/tree-shakeable-manager-providers.md
42+
- migrations/const-to-function-manager-providers.md
4343
- Misc:
4444
- misc/example-apps.md
4545
- misc/bundle-size.md

0 commit comments

Comments
 (0)