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 AsyncNotifier.listenSelf #3797

Merged
merged 1 commit into from
Oct 22, 2024
Merged

Added AsyncNotifier.listenSelf #3797

merged 1 commit into from
Oct 22, 2024

Conversation

rrousselGit
Copy link
Owner

@rrousselGit rrousselGit commented Oct 22, 2024

Related Issues

fixes #3795

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).

  • I have updated the CHANGELOG.md of the relevant packages.
    Changelog files must be edited under the form:

    ## Unreleased fix/major/minor
    
    - Description of your change. (thanks to @yourGithubId)
  • If this contains new features or behavior changes,
    I have updated the documentation to match those changes.

Summary by CodeRabbit

  • New Features

    • Introduced AsyncNotifier.listenSelf and Notifier.listenSelf methods for enhanced state change notifications.
    • Updated Ref.watch to accept auto-dispose providers.
  • Deprecations

    • Deprecated all Ref subclasses and type arguments.
    • Deprecated Ref.listenSelf and Ref.state, recommending Notifier as a replacement.
  • Bug Fixes

    • Various improvements including better error handling and documentation updates.

Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request updates the changelogs for the flutter_riverpod, hooks_riverpod, and riverpod packages to reflect changes in versions 2.6.0 and 2.6.1. Key modifications include the deprecation of all Ref subclasses and the type argument for Ref, alongside the introduction of new methods such as Notifier.listenSelf and AsyncNotifier.listenSelf. Additionally, the Ref.watch method has been updated to accept auto-dispose providers, enhancing its functionality. Documentation improvements were made to clarify these changes.

Changes

File Path Change Summary
packages/flutter_riverpod/CHANGELOG.md Updated for version 2.6.1; deprecated Ref subclasses, Ref.state, Ref.listenSelf; added Notifier.listenSelf, AsyncNotifier.listenSelf; updated Ref.watch.
packages/hooks_riverpod/CHANGELOG.md Updated for version 2.6.1; deprecated Ref subclasses, Ref.state, Ref.listenSelf; added Notifier.listenSelf, AsyncNotifier.listenSelf.
packages/riverpod/CHANGELOG.md Updated for version 2.6.1; deprecated Ref subclasses, Ref.state, Ref.listenSelf; added Notifier.listenSelf, AsyncNotifier.listenSelf; updated Ref.watch.
packages/riverpod/lib/src/async_notifier.dart Added AsyncNotifierBase.listenSelf method for state change listeners; minor documentation updates.
packages/riverpod/lib/src/notifier.dart Added NotifierBase.listenSelf method for immediate listener notifications; no changes to existing methods.

Assessment against linked issues

Objective Addressed Explanation
Add listenSelf to AsyncNotifier (#3795)

Possibly related PRs

  • Removed confusing bullet point #3766: The changes in this PR are related to the documentation of hooks in Riverpod, which is relevant to the overall context of the flutter_riverpod package updates, particularly regarding the deprecation of Ref subclasses and the introduction of Notifier.listenSelf.

Poem

In the meadow where changes bloom,
listenSelf now dispels the gloom.
With Ref laid to rest, we cheer,
New methods bring the future near!
Hops of joy, a dance so spry,
In Riverpod, we leap and fly! 🐇✨


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.

@rrousselGit rrousselGit merged commit b07016c into master Oct 22, 2024
46 of 47 checks passed
@rrousselGit rrousselGit deleted the listenself branch October 22, 2024 12:57
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 (8)
packages/riverpod/lib/src/notifier.dart (1)

Line range hint 24-38: LGTM! Consider enhancing the documentation.

The implementation of listenSelf looks good and aligns with the PR objectives. It successfully addresses the deprecation of ref.listenSelf by providing an equivalent functionality in the NotifierBase class.

Consider adding a code example in the documentation to illustrate how to use the listenSelf method. This would help developers quickly understand its usage. For instance:

@override
void build() {
  listenSelf((previous, next) {
    print('State changed from $previous to $next');
  }, onError: (error, stackTrace) {
    print('An error occurred: $error');
  });
  // ... rest of the build method
}
packages/riverpod/lib/src/async_notifier.dart (1)

36-43: LGTM! Consider expanding the documentation.

The listenSelf method implementation looks good and aligns with the PR objectives. It correctly delegates to the _element.listenSelf method and provides the requested functionality.

Consider expanding the documentation to provide more context about the method's purpose and usage. For example:

/// {@macro notifier.listen}
/// 
/// Registers a listener that will be called whenever the state of this
/// AsyncNotifier changes. This is useful for reacting to state changes
/// without rebuilding the entire widget tree.
///
/// The `listener` function is called with the previous and next state values.
/// An optional `onError` handler can be provided to handle any errors that
/// occur during state changes.

This expanded documentation would provide users with more information about when and how to use the listenSelf method.

packages/riverpod/CHANGELOG.md (2)

1-4: LGTM! Consider updating the documentation.

The addition of AsyncNotifier.listenSelf is in line with the PR objectives and addresses the linked issue #3795. This is a good fix for the oversight in the 2.6.0 release.

Consider updating the relevant documentation to include information about this new method and its usage.


Issues Found: Deprecated Ref usages detected.

Multiple instances of deprecated Ref subclasses, type arguments, ref.state, and ref.listenSelf are still present in the codebase. Additionally, Notifier.listenSelf implementations are missing.

  • Deprecated subclasses and members are used in various packages and tests.
  • Notifier.listenSelf replacements have not been implemented.

Please address these deprecated usages and ensure Notifier.listenSelf is properly implemented.

🔗 Analysis chain

Line range hint 6-12: Significant API changes - ensure thorough testing and documentation updates.

The 2.6.0 release introduces several important API changes:

  1. Deprecation of all Ref subclasses and the Ref type argument.
  2. Deprecation of Ref members using the generic parameter.
  3. Addition of Notifier.listenSelf to replace Ref.listenSelf.
  4. Update to Ref.watch to accept auto-dispose providers.

These changes align with the PR objectives and linked issue, aiming to improve and simplify the API.

To ensure these changes don't introduce breaking changes or regressions, please run the following verification script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of deprecated Ref subclasses and members

# Test: Search for usage of Ref subclasses and deprecated members
rg -i 'class.*extends.*Ref' && echo "Found potential usage of deprecated Ref subclasses"
rg 'Ref<.*>' && echo "Found potential usage of deprecated Ref type argument"
rg 'ref\.state' && echo "Found potential usage of deprecated Ref.state"
rg 'ref\.listenSelf' && echo "Found potential usage of deprecated Ref.listenSelf"

# Test: Check if Notifier.listenSelf is properly implemented
ast-grep --pattern $'class $_ extends Notifier<$_> {
  $$$
  listenSelf($_) {
    $$$
  }
  $$$
}'

Length of output: 70425

packages/flutter_riverpod/CHANGELOG.md (2)

1-3: LGTM. Consider updating the PR description.

The addition of AsyncNotifier.listenSelf in version 2.6.1 directly addresses the objective mentioned in issue #3795. This is a good follow-up to include the missing feature from the 2.6.0 release.

Consider updating the PR description to mention this addition explicitly, as it's the main feature of this release.


Update Changelog Date Order

The dates in the CHANGELOG.md are not in descending order. Please reorder the entries to list the most recent changes first to ensure clarity and proper tracking of updates.

🔗 Analysis chain

Line range hint 5-11: Approve changes, but verify the release date.

The changes in version 2.6.0 are significant and align well with the project's direction:

  1. Deprecating Ref subclasses and type arguments simplifies the API.
  2. Adding Notifier.listenSelf is consistent with the PR objectives.
  3. Enhancing Ref.watch to accept auto-dispose providers improves flexibility.

These changes appear to be well-thought-out and beneficial to users.

However, the release date (2024-10-20) seems to be in the future. Please verify if this is correct or if it's a typo.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the consistency of dates in the changelog

# Check for any dates in the future
future_dates=$(rg '\d{4}-\d{2}-\d{2}' | grep -v "$(date +%Y)-" | grep -v "$(date -d 'last year' +%Y)-")

if [ -n "$future_dates" ]; then
    echo "Warning: Found dates that appear to be in the future:"
    echo "$future_dates"
else
    echo "No future dates found in the changelog."
fi

# Check for date order consistency
if rg '\d{4}-\d{2}-\d{2}' | sort -r | uniq | diff - <(rg '\d{4}-\d{2}-\d{2}' | uniq); then
    echo "Dates are in correct descending order."
else
    echo "Warning: Dates are not in correct descending order."
fi

Length of output: 43695


Script:

#!/bin/bash
# Corrected script to verify the consistency of dates in the changelog

# Get the current date
current_date=$(date +%Y-%m-%d)

# Extract all dates from CHANGELOG.md
all_dates=$(rg '\d{4}-\d{2}-\d{2}' packages/flutter_riverpod/CHANGELOG.md)

# Initialize an empty variable for future dates
future_dates=""

# Iterate through each extracted date
while IFS= read -r line; do
  # Extract the date part
  date=$(echo "$line" | grep -oP '\d{4}-\d{2}-\d{2}')
  
  # Compare the extracted date with the current date
  if [[ "$date" > "$current_date" ]]; then
    future_dates+="$line"$'\n'
  fi
done <<< "$all_dates"

# Check if any future dates were found
if [[ -n "$future_dates" ]]; then
  echo "Warning: Found dates that appear to be in the future:"
  echo "$future_dates"
else
  echo "No future dates found in the changelog."
fi

# Check for date order consistency (descending)
# Extract dates and sort them in descending order
sorted_dates=$(echo "$all_dates" | sort -r)
# Compare the sorted dates with the original order
if [[ "$(echo "$all_dates" | sort -r)" == "$all_dates" ]]; then
  echo "Dates are in correct descending order."
else
  echo "Warning: Dates are not in correct descending order."
fi

Length of output: 7421

packages/hooks_riverpod/CHANGELOG.md (2)

1-3: LGTM! Consider updating the documentation.

The addition of AsyncNotifier.listenSelf is a good catch for functionality that was meant to be included in the previous release. This change improves feature parity and consistency.

Consider updating the relevant documentation to include information about this new method, its usage, and any potential impact on existing code.


Issues Found: Deprecated Ref subclasses and members still in use

The 2.6.0 release has not fully deprecated Ref subclasses and related members. The following issues need to be addressed:

  • Deprecated Ref Subclasses: Multiple files still utilize Ref subclasses such as StateProviderRef, FutureProviderRef, and others.
  • Deprecated Members: Instances of ref.state and ref.listenSelf remain in the codebase.
  • ref.watch Interactions: Usage of ref.watch with .autoDispose providers requires review and possible migration.

Recommended Actions:

  1. Replace Ref Subclasses: Update all instances of Ref subclasses to use Ref directly.
  2. Update Deprecated Members: Refactor code to eliminate the use of ref.state and ref.listenSelf, adopting Notifier and Notifier.listenSelf as replacements.
  3. Review ref.watch Usages: Ensure that interactions with .autoDispose providers are compatible with the updated Ref.watch behavior.
🔗 Analysis chain

Line range hint 5-11: Breaking changes alert: Update code and documentation

This release contains several breaking changes that will require updates to existing code:

  1. Deprecation of all Ref subclasses and its type argument.
  2. Deprecation of Ref members that used its generic parameter.
  3. Addition of Notifier.listenSelf as a replacement for Ref.listenSelf.
  4. Changes to Ref.watch behavior, now accepting auto-dispose providers.

To address these changes:

  1. Update all code using Ref subclasses to use Ref directly.
  2. Replace usages of deprecated Ref members with their new equivalents.
  3. Update code using Ref.listenSelf to use Notifier.listenSelf.
  4. Review and test all usages of Ref.watch with auto-dispose providers.

Run the following script to identify potential areas requiring updates:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of deprecated Ref subclasses and members
rg -i 'Ref<' 
rg 'ref\.state'
rg 'ref\.listenSelf'

# Search for potential Ref.watch usages with auto-dispose providers
rg 'ref\.watch.*\.autoDispose'

Length of output: 67645

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2876c7f and 54bed92.

📒 Files selected for processing (5)
  • packages/flutter_riverpod/CHANGELOG.md (1 hunks)
  • packages/hooks_riverpod/CHANGELOG.md (1 hunks)
  • packages/riverpod/CHANGELOG.md (1 hunks)
  • packages/riverpod/lib/src/async_notifier.dart (1 hunks)
  • packages/riverpod/lib/src/notifier.dart (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
packages/riverpod/lib/src/notifier.dart (1)

Line range hint 24-38: Verify consistency with AsyncNotifier implementation

The listenSelf method has been successfully added to NotifierBase. However, the PR objectives also mention AsyncNotifier.listenSelf.

To ensure consistency across different notifier types, please run the following script:

This will help us verify that the listenSelf method is implemented consistently across both NotifierBase and AsyncNotifier.

✅ Verification successful

Consistency Verified for listenSelf Implementations

Both NotifierBase.listenSelf and AsyncNotifier.listenSelf are implemented consistently, with appropriate type differences reflecting their respective notifier contexts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare listenSelf implementation in NotifierBase and AsyncNotifier

# Search for listenSelf in NotifierBase
echo "NotifierBase.listenSelf implementation:"
rg -A 10 "void listenSelf\(" packages/riverpod/lib/src/notifier.dart

# Search for listenSelf in AsyncNotifier
echo "AsyncNotifier.listenSelf implementation:"
rg -A 10 "void listenSelf\(" packages/riverpod/lib/src/async_notifier.dart

# Note: Adjust the file paths if necessary

Length of output: 1069

packages/flutter_riverpod/CHANGELOG.md (1)

Line range hint 13-1000: Well-maintained changelog with clear upgrade paths.

The changelog demonstrates a consistent history of improvements and maintenance:

  1. Breaking changes are clearly marked.
  2. Migration instructions are provided for significant changes.
  3. There's a good balance of new features, deprecations, and bug fixes.

This structure helps developers understand the evolution of the package and plan their upgrades accordingly.

To further improve the changelog:

  1. Consider adding links to relevant issues or pull requests for major changes.
  2. For breaking changes, you might want to add a brief explanation of the rationale behind the change.

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.

Add listenSelf to AsyncNotifier
1 participant