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

Added StateKeeperOwner.withSavedState and InstanceKeeperOwner.retainedInstance extensions #171

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Jul 7, 2024

Summary by CodeRabbit

  • New Features
    • Introduced new inline functions in the InstanceKeeperOwner interface for retaining instances, enhancing the InstanceKeeper module.
    • Added withSavedState functions to the StateKeeper and StateKeeperOwner interfaces for handling saved states with specific parameters and return types.
  • Tests
    • Implemented tests to validate the saving and restoring of state using the new withSavedState functionality in the StateKeeper module.

@arkivanov arkivanov changed the title Added StateKeeperOwner.withSavedState and InstanceKeeperOwner.retaine… Added StateKeeperOwner.withSavedState and InstanceKeeperOwner.retainedInstance extensions Jul 7, 2024
Copy link

coderabbitai bot commented Jul 7, 2024

Walkthrough

The recent update enhances the InstanceKeeper and StateKeeper modules by adding inline functions for retaining instances and handling saved states more efficiently. These changes provide simplified APIs for better management and restoration of instances and states, improving usability and functionality in the framework.

Changes

File Path Summary
instance-keeper/api/instance-keeper.klib.api Added inline functions to InstanceKeeperOwner for retaining instances.
instance-keeper/src/commonMain/kotlin/.../InstanceKeeperExt.kt Introduced convenience functions in InstanceKeeperOwner for handling instances.
state-keeper/api/android/state-keeper.api Added withSavedState functions in StateKeeperExtKt class.
state-keeper/api/jvm/state-keeper.api Similar to android changes, added withSavedState functions in StateKeeperExtKt class.
state-keeper/api/state-keeper.klib.api Added inline withSavedState functions for StateKeeper and StateKeeperOwner.
state-keeper/src/commonMain/kotlin/.../StateKeeperExt.kt Introduced helper functions for creating and handling objects with saved state.
state-keeper/src/commonTest/kotlin/.../StateKeeperExtTest.kt Added tests for StateKeeperExt ensuring the correct functionality of saving and restoring states.

Poem

In realms of code where instances keep,
And states are saved so deep,
Inline functions spring to life,
Reducing complexity and strife.
Keepers hold, states return,
With each change, our skills do burn.


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 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 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 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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bc46211 and 8c6fa0a.

Files selected for processing (7)
  • instance-keeper/api/instance-keeper.klib.api (1 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (2 hunks)
  • state-keeper/api/android/state-keeper.api (1 hunks)
  • state-keeper/api/jvm/state-keeper.api (1 hunks)
  • state-keeper/api/state-keeper.klib.api (1 hunks)
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt (1 hunks)
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt (1 hunks)
Additional comments not posted (12)
state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt (2)

9-33: Test method looks good! Consider adding more test cases.

The withSavedState_saves_and_restores_state test method effectively verifies that state is saved and restored correctly. Consider adding more test cases to cover edge cases, such as:

  • Handling of null or empty states.
  • Complex state objects.
  • Multiple states with different keys.

35-35: Helper class looks good.

The Holder class is straightforward and serves its purpose well in encapsulating the state for the test.

state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt (2)

16-26: Function implementation looks good.

The withSavedState function provides a clear and concise way to handle saved states. The use of consume and register methods is appropriate. Ensure that the documentation for these methods is comprehensive.


31-42: Function implementation looks good.

The withSavedState function in StateKeeperOwner is a useful convenience wrapper around the withSavedState function in StateKeeper.

instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (4)

31-33: Function implementation looks good.

The retainedInstance function with a key in InstanceKeeperOwner is clear and concise, delegating to the getOrCreate method in InstanceKeeper.


37-38: Function implementation looks good.

The retainedInstance function without a key in InstanceKeeperOwner is clear and concise, delegating to the getOrCreate method in InstanceKeeper.


62-63: Function implementation looks good.

The retainedSimpleInstance function with a key in InstanceKeeperOwner is clear and concise, delegating to the getOrCreateSimple method in InstanceKeeper.


68-69: Function implementation looks good.

The retainedSimpleInstance function without a key in InstanceKeeperOwner is clear and concise, delegating to the getOrCreateSimple method in InstanceKeeper.

state-keeper/api/jvm/state-keeper.api (1)

39-42: API declarations look good.

The new functions withSavedState in StateKeeperExtKt are consistent with the implementation in the StateKeeperExt.kt file.

state-keeper/api/android/state-keeper.api (1)

53-56: LGTM! But verify the function usage in the codebase.

The added functions withSavedState in StateKeeperExtKt enhance the functionality by providing inline methods to handle saved states. These changes are approved.

However, ensure that all function calls to withSavedState are correctly implemented in the codebase.

Verification successful

Let's inspect the relevant lines in StateKeeperExt.kt and StateKeeperExtTest.kt to ensure the function calls to withSavedState match the new signatures.


Function usage verified successfully.

The function calls to withSavedState in StateKeeperExt.kt and StateKeeperExtTest.kt match the new signatures defined in the StateKeeperExtKt class.

  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `withSavedState` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new functions.
rg --type kotlin $'withSavedState'

Length of output: 991


Script:

#!/bin/bash
# Extract the lines around the usage of `withSavedState` in the relevant files to verify the function signatures.

# Extract lines around usage in StateKeeperExt.kt
rg --type kotlin -A 5 -B 5 'withSavedState' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

# Extract lines around usage in StateKeeperExtTest.kt
rg --type kotlin -A 5 -B 5 'withSavedState' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

Length of output: 1904

state-keeper/api/state-keeper.klib.api (1)

35-36: LGTM! But verify the function usage in the codebase.

The added functions withSavedState for StateKeeper and StateKeeperOwner enhance the functionality by providing inline methods to handle saved states. These changes are approved.

However, ensure that all function calls to withSavedState are correctly implemented in the codebase.

Verification successful

All usages of the withSavedState function are correctly implemented in the codebase.

The function calls in both StateKeeperExtTest.kt and StateKeeperExt.kt match the new signatures.

  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `withSavedState` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new functions.
rg --type kotlin $'withSavedState'

Length of output: 991


Script:

#!/bin/bash
# Extracting relevant lines from StateKeeperExtTest.kt and StateKeeperExt.kt to verify the function usage

# Extract lines around the usages in StateKeeperExtTest.kt
rg --context 5 'withSavedState' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

# Extract lines around the usages in StateKeeperExt.kt
rg --context 5 'withSavedState' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

Length of output: 1880

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

33-37: LGTM! But verify the function usage in the codebase.

The added functions retainedInstance and retainedSimpleInstance for InstanceKeeperOwner enhance the functionality by providing inline methods to retain instances. These changes are approved.

However, ensure that all function calls to retainedInstance and retainedSimpleInstance are correctly implemented in the codebase.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8c6fa0a and f1b729a.

Files selected for processing (7)
  • instance-keeper/api/instance-keeper.klib.api (1 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (3 hunks)
  • state-keeper/api/android/state-keeper.api (1 hunks)
  • state-keeper/api/jvm/state-keeper.api (1 hunks)
  • state-keeper/api/state-keeper.klib.api (1 hunks)
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt (1 hunks)
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • instance-keeper/api/instance-keeper.klib.api
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt
  • state-keeper/api/android/state-keeper.api
  • state-keeper/api/jvm/state-keeper.api
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt
Additional comments not posted (2)
state-keeper/api/state-keeper.klib.api (2)

35-35: LGTM! The new function withSavedState is well-implemented.

The function is appropriately designed for saving and restoring state using generics and serialization.


36-36: LGTM! The new function withSavedState is well-implemented.

The function is appropriately designed for saving and restoring state using generics and serialization.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f1b729a and d999bd6.

Files selected for processing (7)
  • instance-keeper/api/instance-keeper.klib.api (1 hunks)
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt (3 hunks)
  • state-keeper/api/android/state-keeper.api (1 hunks)
  • state-keeper/api/jvm/state-keeper.api (1 hunks)
  • state-keeper/api/state-keeper.klib.api (1 hunks)
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt (1 hunks)
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • instance-keeper/api/instance-keeper.klib.api
  • instance-keeper/src/commonMain/kotlin/com/arkivanov/essenty/instancekeeper/InstanceKeeperExt.kt
  • state-keeper/api/android/state-keeper.api
  • state-keeper/api/jvm/state-keeper.api
  • state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt
  • state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt
Additional comments not posted (2)
state-keeper/api/state-keeper.klib.api (2)

35-35: LGTM! The withSavedState function for StateKeeper is well-defined.

The function uses Kotlin's inline and reified type parameters effectively, offering flexibility in state management.


36-36: LGTM! The withSavedState function for StateKeeperOwner is well-defined.

The function is consistent with the StateKeeper version, maintaining flexibility and adhering to best practices.

@arkivanov arkivanov merged commit 4fc079f into master Jul 8, 2024
2 checks passed
@arkivanov arkivanov deleted the withSavedState branch July 8, 2024 15:20
This pull request was closed.
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