feat: Support more strongly-typed ReadTransaction.#55
Merged
Conversation
arv
approved these changes
Sep 13, 2023
| import {unstable_batchedUpdates} from 'react-dom'; | ||
|
|
||
| type Subscribable = Pick<Replicache, 'subscribe'>; | ||
| type Subscribable<Tx, Data> = { |
Contributor
There was a problem hiding this comment.
This should be exported since it is part of the public API.
I think some tools report this but the tool we use for our dts bundling does not. One thing to think about it is that anything that can be reached from the public api should also be part of the public api.
| export function useSubscribe<R extends ReadonlyJSONValue | undefined>( | ||
| rep: Subscribable | null | undefined, | ||
| query: (tx: ReadTransaction) => Promise<R>, | ||
| export function useSubscribe<Tx, D, R extends D>( |
Contributor
There was a problem hiding this comment.
Do you really need 3 type params? Doesn't the following work?
export function useSubscribe<Tx, R>(
r: Subscribable<Tx, R> | null | undefined,
query: (tx: Tx) => Promise<R>,
def: R,
deps: Array<unknown> = [],
): R {
Contributor
There was a problem hiding this comment.
I downloaded this PR and the proposed change works in isolation but it does not work for the tests, and the tests looks right to me. I guess the R extends D is the magic sauce to allow that to work.
useSubscribe() is used by both Replicache and Reflect. Reflect has added a new form of ReadTransaction that has a generic get<T> method. We would like users of replicache-react to be able to use that. However, currently replicache-react pulls in Replicache directly and uses its ReadTransaction. We could publish a new Replicache with the new signature, but then we would have a new problem: that head replicache-react only works with the latest Replicache/Reflect. Solution: Decouple replicache-react and Replicache completely by defining an abstract Subscribable.
6b05d5d to
5279add
Compare
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.
Problem
useSubscribe() is used by both Replicache and Reflect. Reflect has added a new form of ReadTransaction that has a generic get method. We would like users of replicache-react to be able to use that.
However, currently replicache-react pulls in Replicache directly and uses its ReadTransaction. We could publish a new Replicache with the new signature, but then we would have a new problem: that head replicache-react only works with the latest Replicache/Reflect.
Solution
Decouple replicache-react and Replicache completely by defining an abstract Subscribable.