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

Fixed AsyncValue.guard documentation #3440

Closed
wants to merge 2 commits into from

Conversation

drown0315
Copy link
Contributor

@drown0315 drown0315 commented Mar 20, 2024

Fixed the usage of asyncValue.guard in the documentation

Before:

  ///   Future<void> sideEffect() async {
  ///     state = const AsyncValue.loading();
  ///     try {
  ///       final response = await dio.get('my_api/data');
  ///       final data = MyData.fromJson(response);
  ///       state = AsyncValue.data(data);
  ///     } catch (err, stack) {
  ///       state = AsyncValue.error(err, stack);
  ///     }
  ///   }
  /// }

After:

  ///   Future<void> sideEffect() async {
  ///     state = const AsyncValue.loading();
  ///     try {
  ///       final response = await dio.get('my_api/data');
  ///       final data = MyData.fromJson(response);
  ///       if(mounted){
  ///          state = AsyncValue.data(data);
  ///       }
  ///     } catch (err, stack) {
  ///       if(mounted){
  ///          state = AsyncValue.error(err, stack);
  ///       }
  ///     }
  ///   }
  /// }

Because provider may be disposed after await, add code to check if mounted.

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.

Copy link

changeset-bot bot commented Mar 20, 2024

⚠️ No Changeset found

Latest commit: 2774a9b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@drown0315 drown0315 changed the title chore: improved document chore: fixed asyncValue.guard documentation Mar 20, 2024
@drown0315 drown0315 changed the title chore: fixed asyncValue.guard documentation Fixed AsyncValue.guard documentation Mar 20, 2024
@drown0315 drown0315 closed this May 16, 2024
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