Conversation
|
Closed
This file contains hidden or 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
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.
Adds
batchedQuery. It collects calls made at the same time and answers them with one read. This helps when many components each fetch one item as they mount, like rows in a list.Usage
Changes
batchedQuery(callback, lookup, options?)returns a function that takes one query and resolves with its result.callbackgets every query collected in one tick and reads them together.lookuppicks each caller's result from the data. It also gets the query's position in the list.callbackonce. By default they match byhashKey, the same functionqueryuses for its keys. Passkeyto match them another way.limitcaps how many queries onecallbackcall gets. Extra queries go to more calls. This is useful when ids go into a URL.waitsets how long calls are collected, in milliseconds. The default is 0.callbackrejects only the callers in that call. Alookupthat throws rejects only the callers of that query.callbackis running starts a new batch. It never gets data from a batch it was not part of.batchedQueryand theBatchOptionstype are exported from the package.Testing
test/data/batched-query.spec.tswith tests for batching, repeated queries,limit, failed reads, failed lookups, calls made after or during a read, and custom keys.