Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use metadata manager provider APIs v2 around #927

Merged

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Oct 11, 2024

Issue or need

New APIs (v2) were introduced to provide metadata managers in #926

Proposed changes

Let's start using them around for the built-in metadata modules

Some internal APIs have been added to create a metadata manager that belongs to a set of metadata values. Like the ones for built-in modules: Open Graph, standard...

export const provideOpenGraphManager = <Key extends keyof OpenGraph>(
  key: Key,
  ...options: ReadonlyArray<_ProvideNgxMetaModuleManagerOptions<OpenGraph[Key]>>
) =>
  _provideNgxMetaModuleManager<OpenGraph, Key>(
    key,
    [OPEN_GRAPH_KEY],
    withOptions(
      _withModuleManagerNameAttribute(withOpenGraphPropertyAttribute(key)),
      ...options,
    ),
  )

Where key is the key of the object of metadata values that can be set to provide a manager for.

This helper allows abstracting logic for all those kind of modules:

  • Default is setting a <meta> element with same name
    • Despite a custom one may be needed. Like in Open Graph / Twitter Card.
  • JSON Path will be some scope and the key. For instance, Open Graph's url is openGraph scope in the JSON of metadata values (keys to access the module's JSON of values), with the url key in that object. Scope can be multiple keys like in Open Graph profile, under openGraph profile
  • Default is to provide NgxMetaElementsService as dependency (for previous point)
    • Custom dependencies may be needed

Those above are also customized further by every module. For instance, Open Graph sets a custom scope and property attribute to use by default.

The implementation has gone through several rounds of optimizations to improve uncompressed bundle size:

  • Shorten option names in internal objects to be just 1/2 chars.
  • Add utility to indicate key is same as global. To avoid repeat passing the global name around.
  • Remove util to specify Open Graph profile property. Inline it.

Following bundle size optimizations were thought of, but weren't performed:

  • JSON Path to be an array instead of a string. Avoids the utility to convert to it (plus then having to split it back). But nothing much else. Would save 10 bytes. But having first argument as a string is more developer friendly. Worth those 10 bytes.
  • Remove internal module manager withX APIs. It would save 45 bytes of defining them. But eventually just shave 20 bytes of the bundle size. Code is more expressive this way. Worth 20 bytes.

Docs have been updated: custom metadata manager guide.

APIs from #926 are now marked as public. Changing scope to feat

Quick reminders

  • 🤝 I will follow Code of Conduct
  • No existing pull request already does almost same changes
  • 👁️ Contributing docs are something I've taken a look at
  • 📝 Commit messages convention has been followed
  • 💬 TSDoc comments have been added or updated indicating API visibility if API surface has changed.
  • 🧪 Tests have been added if needed. For instance, if adding new features or fixing a bug. Or removed if removing features.
  • ⚙️ API Report has been updated if API surface is altered.

Copy link
Owner Author

davidlj95 commented Oct 11, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @davidlj95 and the rest of your teammates on Graphite Graphite

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.34%. Comparing base (f66dd3f) to head (1463577).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #927      +/-   ##
==========================================
- Coverage   98.16%   97.34%   -0.83%     
==========================================
  Files          85       87       +2     
  Lines         382      376       -6     
  Branches       70       61       -9     
==========================================
- Hits          375      366       -9     
- Misses          3        6       +3     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Oct 11, 2024

📦 Bundle size (Angular v17)

Git ref: 1463577965cf98d4ea3fa9dc467580b3e2ec170d

Module file Size Base size Difference
ngx-meta-core.mjs 3209 bytes (3.2KiB) 2982 bytes (3.0KiB) 7.61%: 227 bytes (227B)
ngx-meta-json-ld.mjs 217 bytes (217B) 220 bytes (220B) -1.36%: -3 bytes (-3B)
ngx-meta-open-graph.mjs 931 bytes (931B) 985 bytes (985B) -5.48%: -54 bytes (-54B)
ngx-meta-routing.mjs 394 bytes (394B) 394 bytes (394B) No change
ngx-meta-standard.mjs 857 bytes (857B) 907 bytes (907B) -5.51%: -50 bytes (-50B)
ngx-meta-twitter-card.mjs 487 bytes (487B) 534 bytes (534B) -8.80%: -47 bytes (-47B)
Total 6095 bytes (6.0KiB) 6022 bytes (5.9KiB) 1.21%: 73 bytes (73B)

Copy link

github-actions bot commented Oct 11, 2024

📦 Bundle size (Angular v15)

Git ref: 1463577965cf98d4ea3fa9dc467580b3e2ec170d

Module file Size Base size Difference
ngx-meta-core.mjs 3661 bytes (3.6KiB) 3346 bytes (3.3KiB) 9.41%: 315 bytes (315B)
ngx-meta-json-ld.mjs 352 bytes (352B) 355 bytes (355B) -.84%: -3 bytes (-3B)
ngx-meta-open-graph.mjs 1172 bytes (1.2KiB) 1254 bytes (1.3KiB) -6.53%: -82 bytes (-82B)
ngx-meta-routing.mjs 557 bytes (557B) 557 bytes (557B) No change
ngx-meta-standard.mjs 959 bytes (959B) 1039 bytes (1.1KiB) -7.69%: -80 bytes (-80B)
ngx-meta-twitter-card.mjs 599 bytes (599B) 664 bytes (664B) -9.78%: -65 bytes (-65B)
Total 7300 bytes (7.2KiB) 7215 bytes (7.1KiB) 1.17%: 85 bytes (85B)

Copy link

github-actions bot commented Oct 11, 2024

📦 Bundle size (Angular v18)

Git ref: 1463577965cf98d4ea3fa9dc467580b3e2ec170d

Module file Size Base size Difference
ngx-meta-core.mjs 3209 bytes (3.2KiB) 2982 bytes (3.0KiB) 7.61%: 227 bytes (227B)
ngx-meta-json-ld.mjs 217 bytes (217B) 220 bytes (220B) -1.36%: -3 bytes (-3B)
ngx-meta-open-graph.mjs 931 bytes (931B) 985 bytes (985B) -5.48%: -54 bytes (-54B)
ngx-meta-routing.mjs 394 bytes (394B) 394 bytes (394B) No change
ngx-meta-standard.mjs 857 bytes (857B) 907 bytes (907B) -5.51%: -50 bytes (-50B)
ngx-meta-twitter-card.mjs 487 bytes (487B) 534 bytes (534B) -8.80%: -47 bytes (-47B)
Total 6095 bytes (6.0KiB) 6022 bytes (5.9KiB) 1.21%: 73 bytes (73B)

Copy link

github-actions bot commented Oct 11, 2024

📦 Bundle size (Angular v16)

Git ref: 1463577965cf98d4ea3fa9dc467580b3e2ec170d

Module file Size Base size Difference
ngx-meta-core.mjs 3701 bytes (3.7KiB) 3386 bytes (3.4KiB) 9.30%: 315 bytes (315B)
ngx-meta-json-ld.mjs 367 bytes (367B) 370 bytes (370B) -.81%: -3 bytes (-3B)
ngx-meta-open-graph.mjs 1202 bytes (1.2KiB) 1284 bytes (1.3KiB) -6.38%: -82 bytes (-82B)
ngx-meta-routing.mjs 572 bytes (572B) 572 bytes (572B) No change
ngx-meta-standard.mjs 974 bytes (974B) 1054 bytes (1.1KiB) -7.59%: -80 bytes (-80B)
ngx-meta-twitter-card.mjs 614 bytes (614B) 679 bytes (679B) -9.57%: -65 bytes (-65B)
Total 7430 bytes (7.3KiB) 7345 bytes (7.2KiB) 1.15%: 85 bytes (85B)

@davidlj95 davidlj95 force-pushed the stacked/feat-add-metadata-manager-provider-apis-v2 branch from 1c48014 to e02ec1d Compare October 13, 2024 15:50
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch 2 times, most recently from d7a62a1 to f81740a Compare October 14, 2024 09:29
@davidlj95 davidlj95 force-pushed the stacked/feat-add-metadata-manager-provider-apis-v2 branch from 3b959cc to d27fae4 Compare October 14, 2024 10:46
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch 5 times, most recently from 104e18b to 2685d8e Compare October 14, 2024 16:45
@davidlj95 davidlj95 force-pushed the stacked/feat-add-metadata-manager-provider-apis-v2 branch from 8cc3a37 to e2de376 Compare October 14, 2024 16:48
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch from 2685d8e to 358de85 Compare October 14, 2024 16:48
@davidlj95 davidlj95 force-pushed the stacked/feat-add-metadata-manager-provider-apis-v2 branch from e2de376 to bdf0527 Compare October 14, 2024 16:54
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch from 33b5d27 to 90d6cf9 Compare October 14, 2024 16:54
Base automatically changed from stacked/feat-add-metadata-manager-provider-apis-v2 to main October 14, 2024 16:59
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch from 90d6cf9 to cfb67a3 Compare October 14, 2024 17:10
@davidlj95 davidlj95 marked this pull request as ready for review October 14, 2024 17:34
@davidlj95 davidlj95 force-pushed the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch from a57df95 to 25cbb5f Compare October 14, 2024 17:53
@davidlj95 davidlj95 changed the title refactor: use metadata manager provider APIs v2 around feat: use metadata manager provider APIs v2 around Oct 14, 2024
@davidlj95 davidlj95 merged commit 43d941c into main Oct 14, 2024
34 checks passed
@davidlj95 davidlj95 deleted the stacked/refactor-use-metadata-manager-provider-apis-v2-around branch October 14, 2024 18:07
Copy link

🎉 This PR is included in version 1.0.0-beta.22 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant