-
-
Notifications
You must be signed in to change notification settings - Fork 147
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(kernel): add last resolver #1976
Conversation
Adds in support for getting last value from the container in instances where are are multiple registered values under the same key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thanks @Vheissu
Co-authored-by: bigopon <9994529+bigopon@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1976 +/- ##
==========================================
- Coverage 88.59% 84.21% -4.38%
==========================================
Files 273 270 -3
Lines 22945 22388 -557
Branches 5305 5220 -85
==========================================
- Hits 20328 18854 -1474
- Misses 2617 3534 +917 ☔ View full report in Codecov by Sentry. |
2.0.0-beta.18 (2024-05-23) **BREAKING CHANGES:** * **dom-queue:** merge dom read and write queues (#1970) ([3a63cde](3a63cde)) **Features:** * **dialog:** ability to specify dialog per open call (#1978) ([7d44ed1](7d44ed1)) * **dialog:** add event manager for custom event handling extension ([7d44ed1](7d44ed1)) * **kernel:** add last resolver (#1976) ([c47817c](c47817c)) * **router-lite:** current route (#1966) ([d966e15](d966e15)) **Bug Fixes:** * **di:** use official metadata instead of weakmap (#1977) ([9aeeffa](9aeeffa)) * **router-lite:** current route subscription disposal (#1969) ([ace4c65](ace4c65)) * **convention:** typing: use array for bindables isntead of object (#1967) ([f1a73d6](f1a73d6)) **Refactorings:** * **collection:** define map & set overrides on the instance instead of prototype (#1975) ([253e92a](253e92a)) * **runtime:** reoganise utils import ([253e92a](253e92a)) * **fetch-client:** extract error codes and cleanup (#1974) ([63ffdc9](63ffdc9)) * **i18n-validation:** replace errors with error codes (#1972) ([f91f31c](f91f31c)) * **dev:** turbo package input glob + ts dev script ([253e92a](253e92a)) **Docs:** * **doc:** updated ISignaler documentation example (#1973) ([e0481d6](e0481d6))
Pull Request
📖 Description
This pull request introduces support for retrieving the last registered value from the Aurelia DI (Dependency Injection) container. In scenarios where multiple values are registered under the same key, the new last resolver ensures that the most recently registered value is always returned.
In the Aurelia DI system, it's possible to register multiple values under the same key. This feature can be useful for various purposes, such as overriding previously registered values without losing them. However, when retrieving these values, the container typically returns all instances associated with the key. There are cases where it's desirable to get only the most recent value, such as when the latest configuration or instance should take precedence.
The implementation of the last resolver involves creating a new resolver that:
This approach leverages the existing functionality of the getAll method to fetch all instances associated with a key and then accesses the last element in the array.
Single Call to getAll: The last resolver optimises performance by making a single call to the getAll method and storing the result.
Direct Element Access: It accesses the last element directly using array indexing, ensuring no modifications are made to the array, which preserves immutability.
Graceful Handling of Empty Arrays: The resolver includes checks to handle cases where no values are registered under the key, returning undefined in such situations.
Usage
The following example demonstrates what happens when you register three different values under the same key.