-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: add util to make (lazy) injection tokens #892
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @davidlj95 and the rest of your teammates on |
7075f97
to
3f13756
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
📦 Bundle size (Angular v17)Git ref:
|
📦 Bundle size (Angular v16)Git ref:
|
📦 Bundle size (Angular v15)Git ref:
|
📦 Bundle size (Angular v18)Git ref:
|
be8c706
to
5163a0e
Compare
5163a0e
to
7449f99
Compare
🎉 This PR is included in version 1.0.0-beta.16 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 theInjectionToken
. 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 addingNgxMeta
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
tomakeInjectionToken
given it also adds the library prefix to the injection token name now.Quick reminders