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

[v1] new implementation without react context #35

Merged
merged 1 commit into from Jan 23, 2020

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Jan 23, 2020

There was an interesting and shocking tweet from @sebmarkbage.
https://twitter.com/sebmarkbage/status/1219836431972978689

Originally, the implementation of this library didn't use context.
Then, people expects the use of context for global state.
I also wanted to seek the possibility of unstable_observedBits.
So, the implementation was changed to context based.

Now, if we follow the suggestion in the tweet, I don't think we need context.
Furthermore, the use of unstable observedBits kept this library away from hitting v1.

This PR is to implement the same API without context.
(Precisely, we no longer have <GlobalStateProvider>, so it's a breaking change.)

The most challenging point is the experimental support of Concurrent Mode,
which was another reason why I used context before.
With the new useGlobalStateProvider, it links React state and global state, which allows "state branching," yay!

This is for v1.

@dai-shi
Copy link
Owner Author

dai-shi commented Jan 23, 2020

There are two concerns in this PR.

a) How to convince the usage without context (zustand is the same)
b) We would get the react#17099 warning, if useGlobalStateProvider is used for opt-in CM support

Still, I think this is more or less promising as v1. (I mean at least better than less common observedBits.)

@dai-shi dai-shi merged commit 455802a into master Jan 23, 2020
@dai-shi dai-shi deleted the implementation-without-context branch January 23, 2020 15:12
@dai-shi
Copy link
Owner Author

dai-shi commented Jan 23, 2020

Tested v1.0.0-alpha.1.
https://github.com/dai-shi/will-this-react-global-state-work-in-concurrent-mode/tree/d9501d598621625c581d8d32d9f7894ebd4b6bfa

  react-hooks-global-state
    check with events from outside
      ✓ check 1: updated properly (8540ms)
      ✓ check 2: no tearing during update (1ms)
      ✓ check 3: ability to interrupt render
      ✓ check 4: proper update after interrupt (2379ms)
    check with useTransaction
      ✓ check 5: updated properly with transition (3635ms)
      ✓ check 6: no tearing with transition (2ms)
      ✓ check 7: proper branching with transition (4485ms)

👏

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.

None yet

1 participant