Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"homepage": "https://replicache.dev",
"repository": "github:rocicorp/replicache-react",
"main": "out/index.js",
"module": "out/index.mjs",
"scripts": {
"format": "prettier --write 'src/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
"check-format": "prettier --check 'src/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
Expand All @@ -19,13 +20,7 @@
"license": "ISC",
"peerDependencies": {
"react": ">=16.0 <19.0",
"react-dom": ">=16.0 <19.0",
"replicache": ">=4.0.1 <12.0 || >7.0.0-beta <7.0.0 || >8.0.0-beta <8.0.0 || >9.0.0-beta <9.0.0 || >10.0.0-alpha <10.0.0 || >10.0.0-beta <10.0.0"
},
"peerDependenciesMeta": {
"replicache": {
"optional": true
}
"react-dom": ">=16.0 <19.0"
},
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
Expand All @@ -42,7 +37,7 @@
"prettier": "^2.4.1",
"react": ">=16.0 <18.0",
"react-dom": ">=16.0 <18.0",
"replicache": ">= 10.0.0",
"replicache": "10.0.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to be ^10.0.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well here's the way I think of it -- we're not actually relying on a particular version . This code is basically do the same thing as the Go pattern of having consumers declare the interfaces for their dependencies, except that in this case the interface is so complex (ReadTransaction) that I'm borrowing the definition in Replicache 10. I could actually pick any version of Replicache that has an interface that is compatible with what useSubscribe is trying to do. I sort of arbitrarily picked 10.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

I was just commenting on locking the version like this. Generally you'd want to use semver.

"snowpack": "^3.8.8",
"typescript": "^4.4.3"
},
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type {ReadonlyJSONValue, ReadTransaction} from 'replicache';
import {useEffect, useState} from 'react';
import {unstable_batchedUpdates} from 'react-dom';

type Subscribable = Pick<Replicache, 'subscribe'>;

// We wrap all the callbacks in a `unstable_batchedUpdates` call to ensure that
// we do not render things more than once over all of the changed subscriptions.

Expand All @@ -21,7 +23,7 @@ function doCallback() {
}

export function useSubscribe<R extends ReadonlyJSONValue>(
rep: Replicache | null | undefined,
rep: Subscribable | null | undefined,
query: (tx: ReadTransaction) => Promise<R>,
def: R,
deps: Array<unknown> = [],
Expand Down