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

Refactored withSavedState, replaced with saveable #172

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Jul 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced saveable functions to replace withSavedState, providing more flexible state-saving capabilities for StateKeeper and StateKeeperOwner.
  • Tests

    • Added tests to ensure the new saveable functions correctly save and restore state.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The updates involve renaming the withSavedState functions to saveable across different file sets (Android, JVM, and KLIB), adjusting their parameters and return types, and introducing new functions for creating mutable and immutable delegated properties to handle state saving and restoration. New tests have been added to ensure these changes work as intended, focusing on automatic state management using StateKeeper.

Changes

File(s) Change Summary
state-keeper/api/android/state-keeper.api, state-keeper/api/jvm/state-keeper.api, state-keeper/api/state-keeper.klib.api Renamed withSavedState functions to saveable with updated parameters and return types
state-keeper/src/commonMain/kotlin/.../StateKeeperExt.kt Renamed functions, added new saveable functions for mutable delegated properties
state-keeper/src/commonTest/kotlin/.../StateKeeperExtTest.kt Added tests for new saveable property functionality

Poem

In the realms of code so bright,
Where state and data take their flight,
With saveable functions, fresh and new,
Your app's state will glide right through.
🌟 A tale of Kotlin's golden dawn,
Where bugs and glitches are withdrawn. 🐇✨


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 4ce4262 and f5a783a.

Files selected for processing (5)
  • 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 (28)
state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt (4)

12-23: LGTM!

The test method saveable_holder_saves_and_restores_state is well-named and covers the state-saving and restoring process thoroughly.


25-37: LGTM!

The test method saveable_property_saves_and_restores_state is well-named and covers the state-saving and restoring process thoroughly.


39-43: LGTM!

The class ComponentWithStateHolder demonstrates the usage of the saveable function with a state holder. The property is well-defined and the usage of the saveable function is clear.


45-46: LGTM!

The class ComponentWithState demonstrates the usage of the saveable function with a state property. The property is well-defined and the usage of the saveable function is clear.

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

40-40: LGTM!

The function declaration for saveable in StateKeeper is correct.


41-41: LGTM!

The function declaration for saveable in StateKeeper with Function1 is correct.


42-42: LGTM!

The function declaration for saveable in StateKeeperOwner is correct.


43-43: LGTM!

The function declaration for saveable in StateKeeperOwner with Function1 is correct.


44-44: LGTM!

The synthetic function declaration for saveable$default in StateKeeper is correct.


45-45: LGTM!

The synthetic function declaration for saveable$default in StateKeeper with Function1 is correct.


46-46: LGTM!

The synthetic function declaration for saveable$default in StateKeeperOwner is correct.


47-47: LGTM!

The synthetic function declaration for saveable$default in StateKeeperOwner with Function1 is correct.

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

25-36: LGTM!

The function saveable in StateKeeper is implemented correctly, with appropriate parameter handling and return type.


53-64: LGTM!

The function saveable in StateKeeperOwner is implemented correctly, with appropriate parameter handling and return type.


78-96: LGTM!

The function saveable for creating mutable delegated properties in StateKeeper is implemented correctly, with appropriate parameter handling and return type.


110-118: LGTM!

The function saveable for creating mutable delegated properties in StateKeeperOwner is implemented correctly, with appropriate parameter handling and return type.

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

54-54: LGTM!

The function declaration for saveable in StateKeeper is correct.


55-55: LGTM!

The function declaration for saveable in StateKeeper with Function1 is correct.


56-56: LGTM!

The function declaration for saveable in StateKeeperOwner is correct.


57-57: LGTM!

The function declaration for saveable in StateKeeperOwner with Function1 is correct.


58-58: LGTM!

The synthetic function declaration for saveable$default in StateKeeper is correct.


59-59: LGTM!

The synthetic function declaration for saveable$default in StateKeeper with Function1 is correct.


60-60: LGTM!

The synthetic function declaration for saveable$default in StateKeeperOwner is correct.


61-61: LGTM!

The synthetic function declaration for saveable$default in StateKeeperOwner with Function1 is correct.

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

35-35: LGTM! Verify the function usage in the codebase.

The new function definition for saveable looks good and is approved.

However, ensure that all function calls to saveable match the new signature.

Verification successful

Verification Successful

The new saveable function definition is correctly integrated and used throughout the codebase.

  • 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 `saveable` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin $'saveable'

Length of output: 1994


Script:

#!/bin/bash
# Extract and review the relevant lines from the test file
rg --context 5 'saveable' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

# Extract and review the relevant lines from the main file
rg --context 5 'saveable' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

Length of output: 3892


37-37: LGTM! Verify the function usage in the codebase.

The new function definition for saveable with transformation functions in StateKeeper looks good and is approved.

However, ensure that all function calls to saveable match the new signature.

Verification successful

Verify the function signatures for saveable.

We need to ensure that all instances of the saveable function match the new signature, including the KSerializer, transformation functions, and an optional key.


Verification Successful: Function signatures match the new definition.

The saveable function usage in the codebase matches the new signature, including the KSerializer, transformation functions, and an optional key.

  • 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 `saveable` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin $'saveable'

Length of output: 1994


Script:

#!/bin/bash
# Description: Inspect lines where `saveable` function is used to verify the function signatures.

# Extract lines around the occurrences of `saveable` to inspect the function signatures.
rg --type kotlin --context 5 'saveable' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt
rg --type kotlin --context 5 'saveable' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

Length of output: 3920


36-36: LGTM! Verify the function usage in the codebase.

The new function definition for saveable in StateKeeperOwner looks good and is approved.

However, ensure that all function calls to saveable match the new signature.


38-38: LGTM! Verify the function usage in the codebase.

The new function definition for saveable with transformation functions in StateKeeperOwner looks good and is approved.

However, ensure that all function calls to saveable match the new signature.

Verification successful

Verification Successful: Function Calls Match New Signature

All function calls to saveable in the codebase match the new signature as defined in StateKeeperOwner.

  • StateKeeperExt.kt
  • StateKeeperExtTest.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

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

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin $'saveable'

Length of output: 1994


Script:

#!/bin/bash
# Description: Extract the function calls to `saveable` in identified files to verify the new function signature.

# Extract lines where `saveable` is called in StateKeeperExt.kt
rg --type kotlin --no-heading --line-number 'saveable' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

# Extract lines where `saveable` is called in StateKeeperExtTest.kt
rg --type kotlin --no-heading --line-number 'saveable' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

Length of output: 1064


Script:

#!/bin/bash
# Description: Extract the full lines of code containing the `saveable` function calls in the identified files to verify the new function signature.

# Extract full lines of code containing `saveable` function calls in StateKeeperExt.kt
sed -n '25p;53p;59p;78p;85,86p;90p;93p;110p;115p' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

# Extract full lines of code containing `saveable` function calls in StateKeeperExtTest.kt
sed -n '12p;26p;40p;46p' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

Length of output: 989


Script:

#!/bin/bash
# Description: Extract a few lines before and after each occurrence of `saveable` to capture the full function call context.

# Extract context around `saveable` function calls in StateKeeperExt.kt
rg --context 2 --type kotlin 'saveable' state-keeper/src/commonMain/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExt.kt

# Extract context around `saveable` function calls in StateKeeperExtTest.kt
rg --context 2 --type kotlin 'saveable' state-keeper/src/commonTest/kotlin/com/arkivanov/essenty/statekeeper/StateKeeperExtTest.kt

Length of output: 2469

@arkivanov arkivanov merged commit 02b1fe7 into master Jul 8, 2024
2 checks passed
@arkivanov arkivanov deleted the saveable branch July 8, 2024 18:43
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