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

Deprecated InstanceKeeper#getOrCreate, added InstanceKeeper#provide and InstanceKeeper#providing extension functions #161

Closed
wants to merge 1 commit into from

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Mar 24, 2024

Summary by CodeRabbit

  • New Features
    • Introduced new functions for obtaining or creating instances in the InstanceKeeper module, enhancing flexibility and usability.
  • Refactor
    • Deprecated older getOrCreate functions in favor of new, more intuitively named provide functions, including lazy variants for deferred instance creation.
  • Tests
    • Updated tests to reflect changes in instance creation methods for consistency.

Copy link

coderabbitai bot commented Mar 24, 2024

Walkthrough

The instance-keeper module has introduced new functions (provide, provideSimple, providing, providingSimple) in InstanceKeeperExtKt for obtaining or creating instances, marking a shift from the older getOrCreate methods. These changes, aimed at enhancing clarity and consistency in method naming, also include lazy variants for deferred instance creation. The update affects both the Android and JVM APIs and modifies the common and test code to align with the new naming convention.

Changes

Files Change Summary
instance-keeper/api/.../instance-keeper.api Added provide, provideSimple, providing, providingSimple functions.
instance-keeper/src/commonMain/.../InstanceKeeperExt.kt Deprecated getOrCreate, introduced provide and lazy variants.
instance-keeper/src/commonTest/.../InstanceKeeperExtTest.kt Replaced getOrCreate with provide in tests.
instance-keeper/src/androidUnitTest/.../AndroidInstanceKeeperTest.kt Updated calls from getOrCreate to provide for instance creation in tests.

🐇✨
In the realm of code, where instances dwell,
A new path unfolds, with tales to tell.
provide and providing, simple and clear,
Out with the old, the new is here.
Through tests and tales, our journey's set,
A hop, a skip, in code, we met.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 39adfe8 and ead3620.
Files selected for processing (4)
  • instance-keeper/api/android/instance-keeper.api (1 hunks)
  • instance-keeper/api/jvm/instance-keeper.api (1 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (2 hunks)
  • instance-keeper/src/commonTest/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExtTest.kt (1 hunks)
Additional comments: 16
instance-keeper/src/commonTest/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExtTest.kt (4)
  • 13-15: The test WHEN_provide_with_key_called_second_time_THEN_returns_same_instance correctly verifies that the provide function returns the same instance when called with the same key. This aligns with the expected behavior of the provide function, ensuring instance uniqueness per key.
  • 21-23: The test WHEN_provide_without_key_called_second_time_THEN_returns_same_instance effectively checks that the provide function without a specified key behaves as expected, returning the same instance upon subsequent calls. This test is crucial for validating the default key behavior of the provide function.
  • 29-31: The test WHEN_provideSimple_with_key_called_second_time_THEN_returns_same_instance accurately ensures that provideSimple with a key returns the same instance on repeated calls. This test is essential for verifying the correct behavior of the provideSimple function, which is intended for simpler use cases without the need for instance destruction.
  • 37-39: The test WHEN_provideSimple_without_key_called_second_time_THEN_returns_same_instance confirms that provideSimple without an explicit key returns the same instance on subsequent calls. This test validates the behavior of provideSimple in scenarios where a key is not provided, ensuring consistency with the expected functionality.
instance-keeper/api/jvm/instance-keeper.api (1)
  • 32-35: The addition of provide, provideSimple, providing, and providingSimple functions to the InstanceKeeperExtKt class is correctly implemented. These functions extend the functionality of the InstanceKeeper component, offering more flexible and intuitive options for instance management. It's important to ensure that these functions are well-documented and their usage is clear to developers.
instance-keeper/api/android/instance-keeper.api (1)
  • 39-42: The addition of provide, provideSimple, providing, and providingSimple functions to the InstanceKeeperExtKt for the Android target mirrors the changes made for the JVM target. This consistency across platforms is crucial for a unified developer experience. Ensure that these functions are accompanied by appropriate documentation and examples to facilitate their adoption.
instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (10)
  • 9-18: The deprecation of getOrCreate in favor of provide is correctly implemented with a clear deprecation message and a ReplaceWith action. This approach facilitates a smooth transition for developers to the new API.
  • 24-24: The provide function is well-implemented, ensuring type safety and correct instance management. It's important to maintain comprehensive documentation for this function, explaining its behavior and usage scenarios.
  • 39-40: The lazy variant providing is correctly implemented, offering a deferred instance creation option. This addition enhances the flexibility of the InstanceKeeper component. Ensure that the lazy behavior is clearly documented for developers.
  • 46-55: The deprecation of getOrCreate for the reified type variant in favor of provide is correctly handled, with a clear message and ReplaceWith directive. This consistency in deprecation strategy across different function variants is commendable.
  • 61-62: The reified type variant of provide is correctly implemented, leveraging Kotlin's reified type parameters for a more intuitive API. Documentation should clearly explain the use of reified types and the benefits they offer in this context.
  • 77-86: The deprecation of getOrCreateSimple in favor of provideSimple is handled well, with a clear deprecation message and a ReplaceWith action. This change aligns with the overall goal of improving the API's intuitiveness and consistency.
  • 94-96: The provideSimple function is implemented correctly, catering to simpler use cases where instance destruction is not required. It's crucial to document this function's intended use cases and limitations clearly.
  • 104-105: The lazy variant providingSimple is a valuable addition, offering deferred creation for simple instances. Documentation should highlight the lazy behavior and its potential use cases to guide developers effectively.
  • 113-122: The deprecation of getOrCreateSimple for reified types in favor of provideSimple is consistent with the deprecation strategy applied to other variants. This clear and consistent approach aids developers in transitioning to the new API.
  • 130-131: The reified type variant of provideSimple is well-implemented, providing a straightforward API for simple instance management. Ensure that the benefits of using reified types in this context are well-documented.

…nd InstanceKeeper#providing extension functions.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 39adfe8 and 0f35434.
Files selected for processing (5)
  • instance-keeper/api/android/instance-keeper.api (1 hunks)
  • instance-keeper/api/jvm/instance-keeper.api (1 hunks)
  • instance-keeper/src/androidUnitTest/kotlin/com/arkivanov/essenty/instancekeeper/AndroidInstanceKeeperTest.kt (3 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (2 hunks)
  • instance-keeper/src/commonTest/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExtTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • instance-keeper/api/android/instance-keeper.api
  • instance-keeper/api/jvm/instance-keeper.api
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt
  • instance-keeper/src/commonTest/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExtTest.kt
Additional comments: 3
instance-keeper/src/androidUnitTest/kotlin/com/arkivanov/essenty/instancekeeper/AndroidInstanceKeeperTest.kt (3)
  • 17-20: The replacement of getOrCreate with provide in the retains_instances test method aligns well with the PR objectives, ensuring that instances are managed more intuitively. The test logic correctly verifies that instances are retained across different instanceKeeper calls.
  • 29-32: The test GIVEN_discardRetainedInstances_is_true_on_restore_THEN_instances_not_retained correctly verifies that instances are not retained when discardRetainedInstances is set to true. The use of provide for instance creation is consistent with the PR's objectives and enhances the clarity of instance management.
  • 41-41: The test GIVEN_discardRetainedInstances_is_true_on_restore_THEN_old_instances_destroyed effectively ensures that old instances are destroyed when discardRetainedInstances is true, aligning with the PR's focus on efficient instance management. The adoption of provide for instance creation is appropriate and supports the PR's goals.

@arkivanov arkivanov closed this Apr 4, 2024
@arkivanov arkivanov deleted the provide branch April 4, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant