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

feat: add imperative api to refresh state #594

Merged
merged 5 commits into from Apr 22, 2022

Conversation

roryabraham
Copy link
Contributor

@roryabraham roryabraham commented Apr 6, 2022

Fixes #593

Overview

This pull request implements a new imperative API called refresh to update NetInfo's state by forcing the native interface to recompute the library's internal state. More detailed in the linked issue πŸ™‚

Test Plan

Keeping the tests pretty simple for now:

  1. Run yarn start:web to run the example web app.
  2. Open and clear the network console.
  3. Tap on NetInfo.fetch – observe that no network request is made to retest internet reachability.
  4. Tap on NetInfo.refresh – observe that a network request is made to retest internet reachability.

There's certainly more that could be done to test this, but personally this is enough to make me confident that this is working as expected.

Screen.Recording.2022-04-05.at.11.43.23.PM.mov

@roryabraham roryabraham marked this pull request as ready for review April 6, 2022 06:44
@roryabraham
Copy link
Contributor Author

roryabraham commented Apr 6, 2022

@matt-oakes Just throwing out an alternate solution – we could also make fetch just do what refresh does now (i.e: always _fetchCurrentState). I'm not sure if there are performance reasons why that would be ill-advised, but it seems kind of unlikely to me that anyone using the fetch API would not want the most up-to-date state possible.

Edit: @mikehardy convinced me the a separate imperative refresh is better: #593 (comment)

@roryabraham
Copy link
Contributor Author

Hiya πŸ‘‹ Friendly reminder that this PR is ready for review πŸ™‚

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks really good, thank you

The only thing I can think of is an addition to the mock

RNCNetInfoMock.fetch.mockResolvedValue(defaultState);

Otherwise looks good?

Sorry for the delay, one of the repos I'm in participates in Google Summer of Code and we had 50 applicants raining PRs on us for the last couple weeks, it has been nutty 🀯

https://github.com/ankidroid/Anki-Android/pulse/monthly

image

@mikehardy mikehardy added awaiting info pending merge A PR that will be merged shortly, waiting for CI or final comment labels Apr 21, 2022
@roryabraham
Copy link
Contributor Author

Thanks for the review! That's a lot of PRs πŸ˜„

Updated the Jest mocks. I'm a bit of a noob when it comes to Jest, so I'm not sure how to test that it works as expected. Let me know if you need further changes. Happy to adjust the PR as needed πŸ‘

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's exactly "the needful", this looks great to me, let's go!

@mikehardy mikehardy merged commit 1d7b751 into react-native-netinfo:master Apr 22, 2022
@mikehardy mikehardy removed the pending merge A PR that will be merged shortly, waiting for CI or final comment label Apr 22, 2022
github-actions bot pushed a commit that referenced this pull request Apr 22, 2022
# [8.3.0](v8.2.0...v8.3.0) (2022-04-22)

### Features

* add imperative api to refresh state ([#594](#594)) ([1d7b751](1d7b751))
@matt-oakes
Copy link
Collaborator

πŸŽ‰ This PR is included in version 8.3.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

@roryabraham
Copy link
Contributor Author

Awesome, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a recheck method to force a state refresh
3 participants