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

refactor: turn main service into a class again #914

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

davidlj95
Copy link
Owner

Issue or need

In #873, the main service NgxMetaService was turned into an abstract class so that it could use a provider to provide the implementation and save a few uncompressed bytes (171 bytes in v18)
However, didn't realize that introducing this change would make the service not tree-shakeable. Given when calling provideNgxMetaCore (or the module-based equivalent API), it would always be provided.
Even if unused.

Proposed changes

Turn it back into a service provided in root. This way it can be removed from the bundle if unused.

Other alternatives considered

Turn it into a lazy injection token

It's not something very Angular'ish. At least yet? So for an external API would seem weird to use by a developer.

Keep it as is, service will be used

It is true that the main service will be almost certainly used. Given it's providing the key piece functionality of the library.

So could assume that it will always be used hence no need to provide it in a tree-shakeable manner. And save those 171 bytes.

But a user may only be interested in one of the utils. So allowing tree-shaking could be interesting for those.

Plus this way APIs follow the traditional Angular way of doing things. So less weird things to expect.

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 10, 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 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.45%. Comparing base (a959b94) to head (447e649).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
- Coverage   99.45%   99.45%   -0.01%     
==========================================
  Files          79       79              
  Lines         370      369       -1     
  Branches       68       68              
==========================================
- Hits          368      367       -1     
  Partials        2        2              

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

Copy link

📦 Bundle size (Angular v18)

Git ref: 447e649d0bf67c9e907f6a505ab58fe09c08d80d

Module file Size Base size Difference
ngx-meta-core.mjs 3022 bytes (3.0KiB) 2853 bytes (2.8KiB) 5.92%: 169 bytes (169B)
ngx-meta-json-ld.mjs 226 bytes (226B) 226 bytes (226B) No change
ngx-meta-open-graph.mjs 986 bytes (986B) 986 bytes (986B) No change
ngx-meta-routing.mjs 394 bytes (394B) 394 bytes (394B) No change
ngx-meta-standard.mjs 994 bytes (994B) 994 bytes (994B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 6136 bytes (6.0KiB) 5967 bytes (5.9KiB) 2.83%: 169 bytes (169B)

Copy link

📦 Bundle size (Angular v17)

Git ref: 447e649d0bf67c9e907f6a505ab58fe09c08d80d

Module file Size Base size Difference
ngx-meta-core.mjs 3022 bytes (3.0KiB) 2853 bytes (2.8KiB) 5.92%: 169 bytes (169B)
ngx-meta-json-ld.mjs 226 bytes (226B) 226 bytes (226B) No change
ngx-meta-open-graph.mjs 986 bytes (986B) 986 bytes (986B) No change
ngx-meta-routing.mjs 394 bytes (394B) 394 bytes (394B) No change
ngx-meta-standard.mjs 994 bytes (994B) 994 bytes (994B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 6136 bytes (6.0KiB) 5967 bytes (5.9KiB) 2.83%: 169 bytes (169B)

Copy link

📦 Bundle size (Angular v16)

Git ref: 447e649d0bf67c9e907f6a505ab58fe09c08d80d

Module file Size Base size Difference
ngx-meta-core.mjs 3442 bytes (3.4KiB) 3270 bytes (3.2KiB) 5.25%: 172 bytes (172B)
ngx-meta-json-ld.mjs 370 bytes (370B) 370 bytes (370B) No change
ngx-meta-open-graph.mjs 1265 bytes (1.3KiB) 1265 bytes (1.3KiB) No change
ngx-meta-routing.mjs 572 bytes (572B) 572 bytes (572B) No change
ngx-meta-standard.mjs 1091 bytes (1.1KiB) 1091 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 645 bytes (645B) 645 bytes (645B) No change
Total 7385 bytes (7.3KiB) 7213 bytes (7.1KiB) 2.38%: 172 bytes (172B)

Copy link

📦 Bundle size (Angular v15)

Git ref: 447e649d0bf67c9e907f6a505ab58fe09c08d80d

Module file Size Base size Difference
ngx-meta-core.mjs 3402 bytes (3.4KiB) 3235 bytes (3.2KiB) 5.16%: 167 bytes (167B)
ngx-meta-json-ld.mjs 355 bytes (355B) 355 bytes (355B) No change
ngx-meta-open-graph.mjs 1235 bytes (1.3KiB) 1235 bytes (1.3KiB) No change
ngx-meta-routing.mjs 557 bytes (557B) 557 bytes (557B) No change
ngx-meta-standard.mjs 1076 bytes (1.1KiB) 1076 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 630 bytes (630B) 630 bytes (630B) No change
Total 7255 bytes (7.1KiB) 7088 bytes (7.0KiB) 2.35%: 167 bytes (167B)

@davidlj95 davidlj95 merged commit 9a6f028 into main Oct 10, 2024
34 checks passed
@davidlj95 davidlj95 deleted the stacked/refactor-turn-main-service-into-a-class-again branch October 10, 2024 12:13
Copy link

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

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