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

[🐴] State transitions #3880

Merged
merged 12 commits into from
May 7, 2024
Merged

[🐴] State transitions #3880

merged 12 commits into from
May 7, 2024

Conversation

estrattonbailey
Copy link
Member

@estrattonbailey estrattonbailey commented May 6, 2024

Reviewing without whitespace helps a bit.

This PR handles state transitions from app foreground to background, including tab focus on web. It also begins to guard async data fetching from being called while another request is in-flight.

To do so, I refactored the state transition logic into a reducer. All updates to this.status go through this reducer. Various side effects are then called.

  • state transition logic is synchronous
  • consecutive state transitions don't clobber each other
    • example: open chat, then nav away while initializing, chat will resolve to correct status
  • certain states only support a subset of actions

This should make it far more clear what's happening, and help us avoid invalid states.

Testing

I recommend uncommenting the debug log within pollEvents for more visibility into what's happening.

  • open chat, go back, should see logs setting the convo to suspended
  • open chat, nav to a different screen (not Messages screen), convo should be backgrounded
  • when navigating back to Messages screen, convo should be suspended
  • on web, switch tabs and switch back, you should see logs going from ready -> backgrounded -> ready
  • on native, background app, should see same logs
  • on web, nav to different screen, then switch tabs, upon return the chat should still be in backgrounded state
  • if you want, uncomment the various throw cases to test error states (some UI is needed)
  • local hot reloads of convo.ts should also work fine

Copy link

render bot commented May 6, 2024

Copy link

github-actions bot commented May 6, 2024

Old size New size Diff
6.88 MB 6.88 MB 2.71 KB (0.04%)

@estrattonbailey estrattonbailey marked this pull request as ready for review May 7, 2024 03:35
(cherry picked from commit 8385579d31500bb4bfb60afeecdc1eb3ddd7e747)
(cherry picked from commit 7f75cd04c3bf81c94662785748698640a84bef51)
(cherry picked from commit b82b552ba4040adf7ead2377541132a386964ff8)
@estrattonbailey estrattonbailey merged commit f78126e into main May 7, 2024
6 checks passed
estrattonbailey added a commit that referenced this pull request May 8, 2024
* origin/main:
  [🐴] Integrate global event bus (#3904)
  fix privacy api type (#3903)
  Let React app replace preload (#3900)
  Remove messages provider (#3902)
  [🐴] State transitions (#3880)
  [🐴] Global event mgmt (#3897)
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.

2 participants