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

Migrate mobx to zustand #583

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

enigma0Z
Copy link

@enigma0Z enigma0Z commented Dec 9, 2024

Overview

  • Implement zustand in replacement to mobx
  • State usage comes from a use<Store>Store() call (such as useDownloadStore() vs. a new StoreClass() call
  • useStores() has been preserved for convenience and refactoring
  • Tests require Jest jsdom environment if they manipulate state
  • State changes must be done via setters, and not direct assignment; storages have had a set() function added to all that allows you to set any property in state; logical setters (e.g. addSever()) have been preserved
  • Code has been added to convert the old mobx store to zustand

Background

mobx is currently blocking an upgrade to Expo 51 & React 18. See PR #539. @thornbill suggested zustand as a reasonable replacement. This PR resolves issue #564 .

Implementation

Zustand is functional (vs. mobx's class-based code). Essentially, instances of StoreClass have been replaced with useStore() calls instead. The stores have been broken out into their individual components, which are serialized and stored separately in AsyncStore, persisted by zustand middleware into the same (already in use) AsyncStorage

State Storage

To access state, use the use<Store>Store() method from the correct store's module (e.g. useDownloadStore().

Test Development

  • Jest tests require jsdom environment to be established
  • This is done via a docstring annotation in the test suites that require it
  • These annotations must be in the first block comment at the top of the file, but they need not be the first lines of that comment
  • Any state changes must be wrapped in an act(() => {<state change here>}) call (you'll see this in most store test suites)

Merging

While I normally don't like squash merges, I think that it's the right call here since this is essentially one wholesale sweep of changes that convert from mobx to zustand. If the package maintainers object, I'm happy to try to rewrite my commit history to be more concise, though I think that's probably not the right call personally.

@enigma0Z enigma0Z force-pushed the feature/migrate-mobx-to-zustand branch from d7d441a to 5da37f1 Compare December 10, 2024 20:04
Copy link
Author

@enigma0Z enigma0Z left a comment

Choose a reason for hiding this comment

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

Note that as I have been developing this I disocvered a bug unrelated to this code change.

In iOS simulator, switching servers causes a logout, even if both servers are logged in. Bug is present on current master branch.

@enigma0Z enigma0Z force-pushed the feature/migrate-mobx-to-zustand branch from dd1ea2e to 17e18fb Compare December 10, 2024 21:54
App.js Outdated Show resolved Hide resolved
@enigma0Z enigma0Z marked this pull request as ready for review December 11, 2024 20:48
@enigma0Z
Copy link
Author

Question, btw: What is the process for an updated version of the app to be built and released to the app stores (particularly iOS) -- the current version is 1.5.0 and is two years old.

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 56.43836% with 159 lines in your changes missing coverage. Please review.

Project coverage is 58.68%. Comparing base (0683213) to head (209a2ac).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
components/NativeShellWebView.js 14.86% 59 Missing and 4 partials ⚠️
App.js 0.00% 26 Missing and 5 partials ⚠️
screens/SettingsScreen.js 16.00% 19 Missing and 2 partials ⚠️
components/VideoPlayer.js 33.33% 9 Missing and 1 partial ⚠️
screens/DevSettingsScreen.js 25.00% 6 Missing ⚠️
components/AudioPlayer.js 50.00% 4 Missing and 1 partial ⚠️
navigation/TabNavigator.js 0.00% 4 Missing and 1 partial ⚠️
components/RefreshWebView.js 50.00% 4 Missing ⚠️
navigation/AppNavigator.js 0.00% 3 Missing ⚠️
stores/DownloadStore.ts 90.32% 3 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
- Coverage   60.10%   58.68%   -1.43%     
==========================================
  Files          47       47              
  Lines         945      973      +28     
  Branches      189      198       +9     
==========================================
+ Hits          568      571       +3     
- Misses        342      365      +23     
- Partials       35       37       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@enigma0Z
Copy link
Author

Codecov Report

Attention: Patch coverage is 50.00000% with 157 lines in your changes missing coverage. Please review.

How much does this report matter for getting things merged? The code I changed was more just getting the state references updated, I suspect the coverage for these was roughly at these numbers before I touched anything.

@thornbill
Copy link
Member

Question, btw: What is the process for an updated version of the app to be built and released to the app stores (particularly iOS) -- the current version is 1.5.0 and is two years old.

Well... this is in progress. We are working on setting up GitHub Actions to build and publish to TestFlight. Previously we used Expo's legacy build service to build and then manually upload. We have been more or less blocked from publishing new releases since the legacy build service was discontinued.

@thornbill
Copy link
Member

Codecov Report

Attention: Patch coverage is 50.00000% with 157 lines in your changes missing coverage. Please review.

How much does this report matter for getting things merged? The code I changed was more just getting the state references updated, I suspect the coverage for these was roughly at these numbers before I touched anything.

It's probably fine 👍

@enigma0Z enigma0Z requested a review from thornbill December 12, 2024 00:19
@enigma0Z
Copy link
Author

Question, btw: What is the process for an updated version of the app to be built and released to the app stores (particularly iOS) -- the current version is 1.5.0 and is two years old.

Well... this is in progress. We are working on setting up GitHub Actions to build and publish to TestFlight. Previously we used Expo's legacy build service to build and then manually upload. We have been more or less blocked from publishing new releases since the legacy build service was discontinued.

Understandable; Do you need any help with this?

@thornbill
Copy link
Member

I don't think so... at least for now the main thing is getting some secrets added to the repo (there have been some other more pressing issues Anthony has been dealing with so this is understandably taking some time) then we can iterate on the action until we get a working build. We have been able to reference Swiftfin so hopefully it will be pretty straightforward once the secrets are available.

@enigma0Z enigma0Z closed this Dec 12, 2024
@enigma0Z enigma0Z reopened this Dec 12, 2024
This was referenced Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants