Skip to content

Commit 2e6bc65

Browse files
authored
Upgrade to Replicache 14 (#159)
1 parent 25468b8 commit 2e6bc65

File tree

9 files changed

+115
-79
lines changed

9 files changed

+115
-79
lines changed

.eslintrc

+16-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
"parserOptions": {
88
"ecmaVersion": 12,
99
"sourceType": "module",
10-
"project": "./tsconfig.json",
10+
"project": "./tsconfig.json"
1111
},
12-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "next", "prettier"],
12+
"extends": [
13+
"eslint:recommended",
14+
"plugin:@typescript-eslint/recommended",
15+
"next",
16+
"prettier"
17+
],
1318
"rules": {
1419
"@typescript-eslint/no-floating-promises": "error",
1520
"@typescript-eslint/naming-convention": [
@@ -29,17 +34,18 @@
2934
"error",
3035
{
3136
"VariableDeclarator": {
32-
"object": true,
33-
},
37+
"object": true
38+
}
3439
},
3540
{
36-
"enforceForRenamedProperties": false,
37-
},
41+
"enforceForRenamedProperties": false
42+
}
3843
],
3944
"no-unused-vars": "off",
40-
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_"}]
45+
"@typescript-eslint/no-unused-vars": [
46+
"error",
47+
{ "argsIgnorePattern": "^_" }
48+
]
4149
},
42-
"plugins": [
43-
"react", "@typescript-eslint"
44-
]
50+
"plugins": ["react", "@typescript-eslint"]
4551
}

.github/workflows/js.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/setup-node@v2
1616
with:
1717
node-version: 16.x
18-
cache: 'npm'
18+
cache: "npm"
1919
- name: npm install
2020
run: npm install
2121
- run: npm run check-format
@@ -29,7 +29,7 @@ jobs:
2929
- uses: actions/setup-node@v2
3030
with:
3131
node-version: 16.x
32-
cache: 'npm'
32+
cache: "npm"
3333
- name: npm install
3434
run: npm install
3535
- run: npm run build

backend/replicache-transaction.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type {
2+
DeepReadonly,
3+
IndexKey,
24
JSONValue,
3-
KeyTypeForScanOptions,
45
ReadTransaction,
6+
ReadonlyJSONValue,
7+
ScanIndexOptions,
8+
ScanNoIndexOptions,
59
ScanOptions,
610
ScanResult,
711
TransactionEnvironment,
@@ -56,6 +60,10 @@ export class ReplicacheTransaction implements WriteTransaction {
5660
return "server";
5761
}
5862

63+
get location() {
64+
return this.environment;
65+
}
66+
5967
get mutationID(): number {
6068
return this._mutationID;
6169
}
@@ -65,6 +73,9 @@ export class ReplicacheTransaction implements WriteTransaction {
6573
}
6674

6775
async put(key: string, value: JSONValue): Promise<void> {
76+
await this.set(key, value);
77+
}
78+
async set(key: string, value: JSONValue): Promise<void> {
6879
this._cache.set(key, { value, dirty: true });
6980
}
7081
async del(key: string): Promise<boolean> {
@@ -90,10 +101,20 @@ export class ReplicacheTransaction implements WriteTransaction {
90101
async isEmpty(): Promise<boolean> {
91102
throw new Error("Method isEmpty not implemented");
92103
}
93-
scan(): ScanResult<string>;
94-
scan<Options extends ScanOptions>(
95-
_options?: Options
96-
): ScanResult<KeyTypeForScanOptions<Options>> {
104+
105+
scan(options: ScanIndexOptions): ScanResult<IndexKey, ReadonlyJSONValue>;
106+
scan(options?: ScanNoIndexOptions): ScanResult<string, ReadonlyJSONValue>;
107+
scan(options?: ScanOptions): ScanResult<IndexKey | string, ReadonlyJSONValue>;
108+
scan<V extends ReadonlyJSONValue>(
109+
options: ScanIndexOptions
110+
): ScanResult<IndexKey, DeepReadonly<V>>;
111+
scan<V extends ReadonlyJSONValue>(
112+
options?: ScanNoIndexOptions
113+
): ScanResult<string, DeepReadonly<V>>;
114+
scan<V extends ReadonlyJSONValue>(
115+
options?: ScanOptions
116+
): ScanResult<IndexKey | string, DeepReadonly<V>>;
117+
scan(): ScanResult<IndexKey | string, ReadonlyJSONValue> {
97118
throw new Error("Method scan not implemented.");
98119
}
99120

frontend/app.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import IssueDetail from "./issue-detail";
3535
import { generateKeyBetween } from "fractional-indexing";
3636
import { useSubscribe } from "replicache-react";
3737
import classnames from "classnames";
38-
import { getPartialSyncState, PartialSyncState } from "./control";
38+
import { getPartialSyncState } from "./control";
3939
import type { UndoManager } from "@rocicorp/undo";
4040
import { HotKeys } from "react-hotkeys";
4141

@@ -358,21 +358,19 @@ const App = ({ rep, undoManager }: AppProps) => {
358358
issueOrder: getIssueOrder(view, orderBy),
359359
});
360360

361-
const partialSync = useSubscribe<
362-
PartialSyncState | "NOT_RECEIVED_FROM_SERVER"
363-
>(
361+
const partialSync = useSubscribe(
364362
rep,
365363
async (tx: ReadTransaction) => {
366364
return (await getPartialSyncState(tx)) || "NOT_RECEIVED_FROM_SERVER";
367365
},
368-
"NOT_RECEIVED_FROM_SERVER"
366+
{ default: "NOT_RECEIVED_FROM_SERVER" as const }
369367
);
370368

371369
const partialSyncComplete = partialSync === "PARTIAL_SYNC_COMPLETE";
372370
useEffect(() => {
373371
console.log("partialSync", partialSync);
374372
if (!partialSyncComplete) {
375-
rep.pull();
373+
void rep.pull();
376374
}
377375
}, [rep, partialSync, partialSyncComplete]);
378376

frontend/issue-detail.tsx

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import PriorityMenu from "./priority-menu";
88
import {
99
Comment,
1010
getIssueComments,
11-
Description,
1211
getIssueDescription,
1312
Issue,
1413
Priority,
@@ -92,39 +91,36 @@ export default function IssueDetail({
9291
}
9392
}, [issues, detailIssueID]);
9493

95-
const issue = useSubscribe<Issue | null>(
94+
const issue = useSubscribe(
9695
rep,
9796
async (tx) => {
9897
if (detailIssueID) {
9998
return (await getIssue(tx, detailIssueID)) || null;
10099
}
101100
return null;
102101
},
103-
null,
104-
[detailIssueID]
102+
{ default: null, dependencies: [detailIssueID] }
105103
);
106-
const description = useSubscribe<Description | null>(
104+
const description = useSubscribe(
107105
rep,
108106
async (tx) => {
109107
if (detailIssueID) {
110108
return (await getIssueDescription(tx, detailIssueID)) || null;
111109
}
112110
return null;
113111
},
114-
null,
115-
[detailIssueID]
112+
{ default: null, dependencies: [detailIssueID] }
116113
);
117114

118-
const comments = useSubscribe<Comment[] | []>(
115+
const comments = useSubscribe(
119116
rep,
120117
async (tx) => {
121118
if (detailIssueID) {
122119
return (await getIssueComments(tx, detailIssueID)) || [];
123120
}
124121
return [];
125122
},
126-
[],
127-
[detailIssueID]
123+
{ default: [], dependencies: [detailIssueID] }
128124
);
129125

130126
const handleClose = useCallback(async () => {

frontend/issue.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export async function putIssue(
134134
tx: WriteTransaction,
135135
issue: Issue
136136
): Promise<void> {
137-
await tx.put(issueKey(issue.id), issue);
137+
await tx.set(issueKey(issue.id), issue);
138138
}
139139

140140
export function issueFromKeyAndValue(
@@ -175,7 +175,7 @@ export async function putIssueDescription(
175175
issueID: string,
176176
description: Description
177177
): Promise<void> {
178-
await tx.put(descriptionKey(issueID), description);
178+
await tx.set(descriptionKey(issueID), description);
179179
}
180180

181181
export const COMMENT_KEY_PREFIX = `comment/`;
@@ -232,7 +232,7 @@ export async function putIssueComment(
232232
tx: WriteTransaction,
233233
comment: Comment
234234
): Promise<void> {
235-
await tx.put(commentKey(comment.issueID, comment.id), comment);
235+
await tx.set(commentKey(comment.issueID, comment.id), comment);
236236
}
237237

238238
const REVERSE_TIMESTAMP_LENGTH = Number.MAX_SAFE_INTEGER.toString().length;

0 commit comments

Comments
 (0)