Skip to content

Commit

Permalink
Upgrade to Replicache 8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Nov 13, 2021
1 parent 51763d0 commit bf1b77f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 54 deletions.
2 changes: 1 addition & 1 deletion backend/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function handlePushRequest(

const t0 = Date.now();
await transact(async (executor) => {
const tx = new WriteTransactionImpl(executor, docID);
const tx = new WriteTransactionImpl(executor, clientID, docID);

let lastMutationID = await getLastMutationID(executor, clientID);
console.log("lastMutationID:", lastMutationID);
Expand Down
6 changes: 3 additions & 3 deletions backend/write-transaction-impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setup(async () => {

test("WriteTransactionImpl", async () => {
await transact(async (tx) => {
const writeTx = new WriteTransactionImpl(tx, "foo");
const writeTx = new WriteTransactionImpl(tx, "c1", "foo");

expect(await writeTx.has("foo")).to.be.false;
expect(await writeTx.get("foo")).to.be.undefined;
Expand All @@ -21,15 +21,15 @@ test("WriteTransactionImpl", async () => {
expect(await writeTx.get("foo")).to.equal("bar");

// They don't overlap until one flushes and the other is reloaded.
const writeTx2 = new WriteTransactionImpl(tx, "foo");
const writeTx2 = new WriteTransactionImpl(tx, "c1", "foo");
expect(await writeTx2.has("foo")).to.be.false;
expect(await writeTx2.get("foo")).to.be.undefined;

// TODO: scan, isEmpty

// Go ahead and flush one
await writeTx.flush();
const writeTx3 = new WriteTransactionImpl(tx, "foo");
const writeTx3 = new WriteTransactionImpl(tx, "c1", "foo");
expect(await writeTx3.has("foo")).to.be.true;
expect(await writeTx3.get("foo")).to.equal("bar");
});
Expand Down
8 changes: 7 additions & 1 deletion backend/write-transaction-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import { Executor } from "./db";
* transaction.
*/
export class WriteTransactionImpl implements WriteTransaction {
private _clientID: string;
private _docID: string;
private _executor: Executor;
private _cache: Map<
string,
{ value: JSONValue | undefined; dirty: boolean }
> = new Map();

constructor(executor: Executor, docID: string) {
constructor(executor: Executor, clientID: string, docID: string) {
this._clientID = clientID;
this._docID = docID;
this._executor = executor;
}

get clientID(): string {
return this._clientID;
}

async put(key: string, value: JSONValue): Promise<void> {
this._cache.set(key, { value, dirty: true });
}
Expand Down
65 changes: 18 additions & 47 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"react-dom": "17.0.2",
"react-draggable": "^4.4.3",
"react-hotkeys": "^1.1.4",
"replicache": "^7.0.0",
"replicache-react": "^2.0.0",
"replicache": "^8.0.0",
"replicache-react": "^2.4.0",
"ws": "^8.2.3",
"zod": "^3.11.6"
},
Expand Down

0 comments on commit bf1b77f

Please sign in to comment.