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

chore: add util to make (lazy) injection tokens #892

Merged

Conversation

davidlj95
Copy link
Owner

Issue or need

See #891

Proposed changes

Add a util to define injection tokens & its factories in a lazy manner. This way, if no one needs them, they won't be created. Neither their factories will end up in the production bundle.

Came with this APIs eventually, though first iteration was <T>(...args: ConstructorParameters<InjectionToken<T>>) => InjectionToken<T>. Then, thought that maybe could uncouple to the parameters of the InjectionToken. So went with <T>(injectionTokenFactory: () => InjectionToken<T>) => T. But then when using the API, we're adding yet another level of indent. Finally, thought that we're also adding NgxMeta around in our injection tokens. If we supplied the name here, we could avoid repeating that string around. Plus save the { factory: [...] } object declaration around. So here it is. Tried it a bit with _HEAD_ELEMENT_UPSERT_OR_REMOVE. Works fine.

The name went from lazyInjectionToken to makeInjectionToken given it also adds the library prefix to the injection token name now.

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

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

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

@davidlj95 davidlj95 force-pushed the stacked/chore-add-util-to-make-lazy-injection-tokens branch from 7075f97 to 3f13756 Compare October 7, 2024 15:39
@davidlj95 davidlj95 marked this pull request as draft October 7, 2024 15:40
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.46%. Comparing base (67f4527) to head (7449f99).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #892   +/-   ##
=======================================
  Coverage   99.45%   99.46%           
=======================================
  Files          78       79    +1     
  Lines         366      372    +6     
  Branches       72       73    +1     
=======================================
+ Hits          364      370    +6     
  Partials        2        2           

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

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v17)

Git ref: 3f13756654734a3708da47f222ee4ac6f7ed444f

Module file Size Base size Difference
ngx-meta-core.mjs 2820 bytes (2.8KiB) 2816 bytes (2.8KiB) .14%: 4 bytes (4B)
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5981 bytes (5.9KiB) 5977 bytes (5.9KiB) .06%: 4 bytes (4B)

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v16)

Git ref: 7449f993264a5377881041043b7a21293fd37e7d

Module file Size Base size Difference
ngx-meta-core.mjs 3255 bytes (3.2KiB) 3255 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 368 bytes (368B) 368 bytes (368B) No change
ngx-meta-open-graph.mjs 1263 bytes (1.3KiB) 1263 bytes (1.3KiB) No change
ngx-meta-routing.mjs 641 bytes (641B) 641 bytes (641B) No change
ngx-meta-standard.mjs 1087 bytes (1.1KiB) 1087 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 645 bytes (645B) 645 bytes (645B) No change
Total 7259 bytes (7.1KiB) 7259 bytes (7.1KiB) No change

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v15)

Git ref: 7449f993264a5377881041043b7a21293fd37e7d

Module file Size Base size Difference
ngx-meta-core.mjs 3220 bytes (3.2KiB) 3220 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 353 bytes (353B) 353 bytes (353B) No change
ngx-meta-open-graph.mjs 1233 bytes (1.3KiB) 1233 bytes (1.3KiB) No change
ngx-meta-routing.mjs 626 bytes (626B) 626 bytes (626B) No change
ngx-meta-standard.mjs 1072 bytes (1.1KiB) 1072 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 630 bytes (630B) 630 bytes (630B) No change
Total 7134 bytes (7.0KiB) 7134 bytes (7.0KiB) No change

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v18)

Git ref: 7449f993264a5377881041043b7a21293fd37e7d

Module file Size Base size Difference
ngx-meta-core.mjs 2812 bytes (2.8KiB) 2816 bytes (2.8KiB) -.14%: -4 bytes (-4B)
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5973 bytes (5.9KiB) 5977 bytes (5.9KiB) -.06%: -4 bytes (-4B)

@davidlj95 davidlj95 force-pushed the stacked/chore-add-util-to-make-lazy-injection-tokens branch 3 times, most recently from be8c706 to 5163a0e Compare October 7, 2024 16:19
@davidlj95 davidlj95 force-pushed the stacked/chore-add-util-to-make-lazy-injection-tokens branch from 5163a0e to 7449f99 Compare October 7, 2024 16:26
@davidlj95 davidlj95 marked this pull request as ready for review October 7, 2024 18:03
@davidlj95 davidlj95 merged commit b49c0ff into main Oct 7, 2024
34 checks passed
@davidlj95 davidlj95 deleted the stacked/chore-add-util-to-make-lazy-injection-tokens branch October 7, 2024 18:04
Copy link

github-actions bot commented Oct 8, 2024

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

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