Skip to content

Removed useless reified keywords from InstanceKeeper extensions #194

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

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Apr 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced several new methods to enhance the management of retained resources and closeable items, offering a more streamlined approach for retrieving or creating instances across multiple platforms.
    • Expanded the API to support both simple and resource-managing instances via a refreshed interface.
  • Refactor

    • Simplified generic instance handling by adjusting type management, leading to a cleaner and more consistent usage of the instance management API.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

The changes extend the instance management APIs by adding new methods that allow for retrieving or creating closeable and retained instances. New public methods were added to the InstanceKeeperExtKt class (for Android and JVM) and to the InstanceKeeperOwner interface, and the inline functions’ type parameters have been updated to remove the reified modifier. These modifications standardize instance creation and retention across different platforms while simplifying type handling in the inline functions.

Changes

File(s) Change Summary
instance-keeper/api/android/.../InstanceKeeperExtKt
instance-keeper/api/jvm/.../InstanceKeeperExtKt
Added four new public methods: getOrCreateCloseable, retainedCloseable, retainedInstance, and retainedSimpleInstance to enhance instance management for both Android and JVM targets.
instance-keeper/api/instance-keeper.klib.api Added several new inline functions to the InstanceKeeperOwner interface, providing methods for retained and closeable instance management, and removed the old definitions tied to InstanceKeeper.
instance-keeper/src/commonMain/kotlin/.../InstanceKeeperExt.kt Updated inline function signatures by removing the reified keyword from type parameters in the functions for closeable and retained instance creation.

Sequence Diagram(s)

sequenceDiagram
  participant Owner as InstanceKeeperOwner
  participant Ext as InstanceKeeperExtKt
  participant Keeper as InstanceKeeper
  participant Factory as Factory Function

  Owner->>+Ext: getOrCreateCloseable(key, factory)
  Ext->>Keeper: Lookup instance by key
  alt Instance exists
    Keeper-->>Ext: Return existing AutoCloseable instance
  else New instance needed
    Ext->>Factory: Create new AutoCloseable instance
    Factory-->>Ext: Return new instance
  end
  Ext-->>-Owner: Return AutoCloseable instance
Loading
sequenceDiagram
  participant Owner as InstanceKeeperOwner
  participant Ext as InstanceKeeperExtKt
  participant Factory as Factory Function

  Owner->>+Ext: retainedInstance(key, factory)
  alt Instance exists
    Ext-->>Owner: Return retained instance
  else New instance needed
    Ext->>Factory: Create new instance
    Factory-->>Ext: Return new instance
  end
  Ext-->>-Owner: Return retained instance
Loading

Possibly related PRs

Poem

Hop along, my code-bound friend,
New functions bloom as notes we send.
Retained and closeable, neat and clear,
Our instances now leap without fear.
With each new method, we cheer and bound—
A rabbit’s joy in code profound!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2e9cb5 and 6f506fa.

📒 Files selected for processing (4)
  • instance-keeper/api/android/instance-keeper.api (1 hunks)
  • instance-keeper/api/instance-keeper.klib.api (1 hunks)
  • instance-keeper/api/jvm/instance-keeper.api (1 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build on macOS
  • GitHub Check: Build on Linux
🔇 Additional comments (12)
instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (4)

45-56: Approval: Removed reified keyword from getOrCreateCloseable function.

The removal of the reified keyword from the type parameter is appropriate since runtime type information is not actually needed in the implementation. This change aligns with the use of explicit key parameter rather than relying on runtime type information.


80-81: Approval: Removed reified keyword from retainedInstance function.

Good simplification by removing the unnecessary reified keyword. The function implementation doesn't require runtime type information since an explicit key is provided.


102-103: Approval: Removed reified keyword from retainedCloseable function.

Appropriate removal of the reified keyword as the function doesn't need runtime type information when an explicit key is provided. This change improves API consistency.


153-154: Approval: Removed reified keyword from retainedSimpleInstance function.

Good change removing the unnecessary reified keyword. The function works fine without runtime type information when using explicit keys.

instance-keeper/api/instance-keeper.klib.api (4)

41-41: Approval: Added non-reified retainedInstance function to API.

This addition properly exposes the new non-reified version of the retainedInstance function for Kotlin multiplatform targets.


43-43: Approval: Added non-reified retainedSimpleInstance function to API.

Good addition of the non-reified version of retainedSimpleInstance to the API, ensuring consistency across the library.


44-44: Approval: Added non-reified getOrCreateCloseable function to API.

The non-reified version of getOrCreateCloseable is properly added to the API for Kotlin multiplatform targets.


45-45: Approval: Added non-reified retainedCloseable function to API.

Good addition of the non-reified version of retainedCloseable to the API, maintaining consistency with the implementation changes.

instance-keeper/api/jvm/instance-keeper.api (2)

34-34: Approval: Added getOrCreateCloseable to JVM API.

Good addition of the getOrCreateCloseable function to the JVM API, ensuring the functionality is available on the JVM platform.


36-38: Approval: Added convenience functions to JVM API.

These added functions (retainedCloseable, retainedInstance, and retainedSimpleInstance) properly expose the non-reified implementations to JVM consumers, maintaining API consistency across platforms.

instance-keeper/api/android/instance-keeper.api (2)

41-41: Approval: Added getOrCreateCloseable to Android API.

Appropriate addition of the getOrCreateCloseable function to the Android API, ensuring the functionality is available for Android consumers.


43-45: Approval: Added convenience functions to Android API.

The added functions (retainedCloseable, retainedInstance, and retainedSimpleInstance) properly expose the non-reified implementations to Android consumers, maintaining API consistency with other platforms.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arkivanov arkivanov merged commit 40d48b3 into master Apr 2, 2025
3 checks passed
@arkivanov arkivanov deleted the reified branch April 2, 2025 16:46
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