Give transformers access to the full, combined reducer state #682
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.
For example, this is useful if you have a transformer that needs to filter items in one reducer based on values in another reducer.
Let's say we're building a chat app, where we'd like the 100 most recent messages and the sender info shown right when the app starts up (without making a trip to the server). We have a
users
reducer, which is a bunch of user data objects keyed byuserId
. We also have amessages
reducer, which is an ordered list of message data objects, with asenderId
property that refers to theuserId
of the sender. We'd like to build a transformer that persists only the top 100 messages in themessages
reducer, along with all the users in theuser
reducer that correspond to the senders of those 100 messages.Right now, this isn't possible. When persisting users in the
users
reducer, the transformer isn't able to access themessages
reducer to figure out which users are senders of the top 100 messages.With this PR, that transformer can be written as: