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 key parameter to StateKeeper Android extensions #182

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Nov 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new method overloads for StateKeeper and stateKeeper, allowing users to specify a key for enhanced state management.
    • Enhanced flexibility in state management with additional parameters in existing methods.
  • Bug Fixes

    • Updated existing method signatures for better parameter handling and consistency.
  • Refactor

    • Improved implementation logic to utilize the new key parameter for dynamic state management.

Verified

This commit was signed with the committer’s verified signature.
vEnhance Evan Chen
Copy link

coderabbitai bot commented Nov 26, 2024

Walkthrough

The changes in this pull request introduce new method signatures and overloads in the AndroidExtKt and StateKeeperExtKt classes within the com.arkivanov.essenty.statekeeper package. Specifically, new String parameters are added to the StateKeeper and stateKeeper methods, enhancing their flexibility for state management. The modifications also include updates to existing method signatures to accommodate these new parameters, allowing for more dynamic state handling.

Changes

File Path Change Summary
state-keeper/api/android/state-keeper.api - Added overloaded methods in AndroidExtKt: StateKeeper(SavedStateRegistry, String, boolean, Function0) and stateKeeper(SavedStateRegistryOwner, String, Function0).
- Added synthetic default methods for these signatures.
- Updated saveable methods in StateKeeperExtKt to include a String parameter.
state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt - Updated StateKeeper function to include a new key: String parameter.
- Modified implementation to use the key parameter instead of a hardcoded constant.
- Updated stateKeeper extension function to include the new key parameter.

Possibly related PRs

🐰 In the land of code where rabbits play,
New methods hop in, brightening the day.
With keys for state, so clever and neat,
Our state management is now quite a treat!
So let’s celebrate with a joyful cheer,
For changes that bring us all good cheer! 🥕✨


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>, 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 resolve resolve all the CodeRabbit review comments.
  • @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.

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

🧹 Outside diff range and nitpick comments (2)
state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt (1)

Line range hint 40-62: Consider using the provided key for Bundle storage.

Currently, while the registry key is customizable, the inner Bundle still uses the hardcoded KEY_STATE constant. This could potentially cause conflicts if multiple StateKeepers use different registry keys but share the same inner Bundle key.

Consider using the provided key for Bundle storage as well:

- ?.getSerializableContainer(key = KEY_STATE)
+ ?.getSerializableContainer(key = key)

- putSerializableContainer(key = KEY_STATE, value = dispatcher.save())
+ putSerializableContainer(key = key, value = dispatcher.save())
state-keeper/api/android/state-keeper.api (1)

Line range hint 46-54: LGTM: Well-structured API changes

The changes to saveable methods are consistent with the new key parameter support. The API design:

  • Maintains backward compatibility through default parameters
  • Provides consistent overloads for both StateKeeper and StateKeeperOwner
  • Preserves the existing method signatures while extending functionality

Consider adding KDoc comments to explain the purpose and usage of the key parameter in the source files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between afdcd68 and b02c25d.

📒 Files selected for processing (2)
  • state-keeper/api/android/state-keeper.api (1 hunks)
  • state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt (2 hunks)
🔇 Additional comments (5)
state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt (4)

21-28: LGTM! Clean refactoring to support new key parameter.

The changes maintain backward compatibility by delegating to the new overload with the default KEY_STATE constant.


76-81: LGTM! Clean refactoring of the extension function.

The changes maintain backward compatibility by delegating to the new overload with the default KEY_STATE constant.


92-102: LGTM! Well-documented and properly implemented extension overload.

The new overload is cleanly implemented and maintains consistency with the existing pattern.


Line range hint 1-102: Verify existing StateKeeper usages in the codebase.

Since these changes add new overloads while maintaining backward compatibility, let's verify that existing usages are not affected.

✅ Verification successful

Let me check the test file to verify the usage patterns and ensure compatibility.


Changes are safe and maintain backward compatibility

The verification confirms that:

  • The KEY_STATE constant is only used within AndroidExt.kt and not referenced elsewhere
  • Existing usages in tests demonstrate compatibility with both extension methods (stateKeeper()) and direct constructor calls (StateKeeper())
  • The new overloads maintain the same behavior while adding optional parameters
  • Test cases cover critical scenarios including state saving/restoring and the new isSavingAllowed and discardSavedState parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing StateKeeper usages to ensure they're not affected
rg -l "StateKeeper\(" --type kotlin

# Search for any potential custom keys already in use
rg "KEY_STATE" --type kotlin

Length of output: 916


Script:

#!/bin/bash
# Check the test file content to understand usage patterns
cat state-keeper/src/androidUnitTest/kotlin/com/arkivanov/essenty/statekeeper/AndroidStateKeeperTest.kt

Length of output: 4113

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

2-8: Verify the impact of new StateKeeper API signatures

The addition of String parameter for custom keys is a good enhancement. However, since this is a public API change, we should ensure:

  1. The changes are documented in the changelog
  2. Migration guide is provided for users upgrading from previous versions
  3. The default key value maintains backward compatibility

Let's verify the usage and documentation:

✅ Verification successful

Let me gather more information about the implementation and documentation to verify if this is a breaking change.


Let me try a different approach to check the implementation details and default values.


API changes maintain backward compatibility

The verification shows that the API changes are non-breaking:

  • The original StateKeeper function is preserved with the same default parameters
  • The new overload with key parameter uses KEY_STATE constant as the default key in the original function
  • Both functions share the same default values for discardSavedState and isSavingAllowed

The changes safely extend the API by adding optional key customization while maintaining full backward compatibility with existing code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for changelog updates and documentation
fd -e md -e txt . | xargs rg -i "statekeeper.*key|breaking.*change"

# Look for existing usages that might need migration
rg "StateKeeper\s*\(" --type kotlin

Length of output: 1134


Script:

#!/bin/bash
# Check implementation of StateKeeper to see if it's backward compatible
ast-grep --pattern 'fun StateKeeper($$$) {
  $$$
}'

# Check for any CHANGELOG or release notes
fd "CHANGELOG|RELEASE" --type f | xargs cat

# Check the default key implementation
rg "key\s*=.*default" --type kotlin

Length of output: 137


Script:

#!/bin/bash
# Check the implementation file for default values and backward compatibility
rg -A 10 "fun StateKeeper" state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt

# Look for any documentation or comments about the key parameter
rg -B 2 "fun StateKeeper" state-keeper/src/androidMain/kotlin/com/arkivanov/essenty/statekeeper/AndroidExt.kt

# Check for any tests that might show the default behavior
rg -A 5 "class.*Test" state-keeper/src/androidUnitTest/kotlin/com/arkivanov/essenty/statekeeper/AndroidStateKeeperTest.kt

Length of output: 1898

@arkivanov arkivanov merged commit 0879b2d into master Nov 26, 2024
3 checks passed
@arkivanov arkivanov deleted the state-keeper-key branch November 26, 2024 22:30
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.

None yet

1 participant