-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
[WIP] [simple-cache-provider] Subscriptions #13216
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React: size: 🔺+2.4%, gzip: 🔺+1.9% ReactDOM: size: 🔺+0.7%, gzip: 🔺+0.7% Details of bundled changes.Comparing: 21ac62c...0830626 react
react-dom
react-art
react-test-renderer
react-reconciler
simple-cache-provider
react-native-renderer
Generated by 🚫 dangerJS |
Currently, context can only be read by a special type of component, ContextConsumer. We want to add support to all fibers, including classes and functional components. Each fiber may read from one or more contexts. To enable quick, mono- morphic access of this list, we'll store them on a fiber property.
unstable_read can be called anywhere within the render phase. That includes the render method, getDerivedStateFromProps, constructors, functional components, and context consumer render props. If it's called outside the render phase, an error is thrown.
Wasn't being used.
Currently, the `expirationTime` field represents the pending work of both the fiber itself — including new props, state, and context — and of any updates in that fiber's subtree. This commit adds a second field called `childExpirationTime`. Now `expirationTime` only represents the pending work of the fiber itself. The subtree's pending work is represented by `childExpirationTime`. The biggest advantage is it requires fewer checks to bailout on already finished work. For most types of work, if the `expirationTime` does not match the render expiration time, we can bailout immediately without any further checks. This won't work for fibers that have `shouldComponentUpdate` semantics (class components), for which we still need to check for props and state changes explicitly.
Adds subscription support. A subscription is created the first time a value is read from the cache, and disposed once we detect that all the consumers have unmounted. On the initial mount, subscriptions are stored in a special map on the nearest provider (`_pendingChildSubscriptionsMap`). When the initial mount commits, the subscriptions are transferred from the pending set to the newly mounted provider.
acdlite
force-pushed
the
createobservableresource
branch
from
July 17, 2018 04:00
9369362
to
0830626
Compare
Closed in favor of #13337 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Depends on #13139
Adds subscription support to simple-cache-provider. A subscription is created the first time a value is read from the cache, and disposed once we detect that all the consumers have unmounted.
On the initial mount, subscriptions are stored in a special map on the nearest provider (
_pendingChildSubscriptionsMap
). When the initial mount commits, the subscriptions are transferred from the pending set to the newly mounted provider.The advantage of this approach over the one used by the create-subscription package (and most third-party libraries) is that the context API is used to ensure consistency: if multiple components read the same value from the cache, they will always receive the same value. Subscriptions are created per key, not per component.
Because consistency is guaranteed between components, it's ok if the tree is out of sync with the latest subscription value. We never have to revert back to sync mode. In other words, the React tree is eventually consistent with the subscription, but multiple components within a single React tree are always consistent with each other.
TODO:
cache.purge
cache.preload
calculateChangedBits
API to optimize subscription updatesFollow ups: