Skip to content

Commit 761153f

Browse files
committed
Simplify ExperimentalCreateKVStore Write class.
1 parent 2f5b263 commit 761153f

File tree

6 files changed

+19
-103
lines changed

6 files changed

+19
-103
lines changed

packages/example/mobile-react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@react-native-replicache/example-client-shared": "0.0.0",
2222
"@react-native-replicache/example-shared": "0.0.0",
23-
"@react-native-replicache/react-native-quick-sqlite": "0.0.2",
23+
"@react-native-replicache/react-native-quick-sqlite": "0.0.3",
2424
"expo": "~48.0.1",
2525
"expo-build-properties": "0.5.1",
2626
"expo-crypto": "^12.0.0",

packages/react-native-quick-sqlite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-native-replicache/react-native-quick-sqlite",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"main": "./dist/commonjs/index.js",
55
"module": "./dist/module/index.js",
66
"react-native": "./src/index.ts",

packages/react-native-quick-sqlite/src/replicache-quick-sqlite-read-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class ReplicacheQuickSQLiteReadImpl
88
{
99
private _closed = false;
1010

11-
constructor(private readonly _tx: ReplicacheQuickSQLiteTransaction) {}
11+
constructor(protected readonly _tx: ReplicacheQuickSQLiteTransaction) {}
1212

1313
async has(key: string) {
1414
const unsafeValue = await this._tx.get(key);

packages/react-native-quick-sqlite/src/replicache-quick-sqlite-write-impl-base.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,22 @@
1-
import { ReplicacheQuickSQLiteReadImpl } from "./replicache-quick-sqlite-read-impl";
2-
import { ReplicacheQuickSQLiteTransaction } from "./replicache-quick-sqlite-transaction";
3-
import {
4-
deleteSentinel,
5-
ReplicacheQuickSQLiteWriteImplBase,
6-
} from "./replicache-quick-sqlite-write-impl-base";
7-
8-
export class ReplicacheQuickSQLiteWriteImpl extends ReplicacheQuickSQLiteWriteImplBase {
9-
private readonly _tx: ReplicacheQuickSQLiteTransaction;
10-
private _closed = false;
11-
12-
constructor(tx: ReplicacheQuickSQLiteTransaction) {
13-
super(new ReplicacheQuickSQLiteReadImpl(tx));
14-
this._tx = tx;
15-
}
1+
import { ExperimentalCreateKVStore, ReadonlyJSONValue } from "replicache";
162

17-
async commit() {
18-
if (this._pending.size === 0) {
19-
return;
20-
}
21-
22-
await Promise.all(
23-
[...this._pending.entries()].map(async ([key, value]) => {
24-
if (value === deleteSentinel) {
25-
await this._tx.delete(key);
26-
} else {
27-
const jsonValueString = JSON.stringify(value);
28-
await this._tx.upsert(key, jsonValueString);
29-
}
30-
})
31-
);
3+
import { ReplicacheQuickSQLiteReadImpl } from "./replicache-quick-sqlite-read-impl";
324

33-
this._pending.clear();
5+
export class ReplicacheQuickSQLiteWriteImpl
6+
extends ReplicacheQuickSQLiteReadImpl
7+
implements
8+
Awaited<ReturnType<ReturnType<ExperimentalCreateKVStore>["write"]>>
9+
{
10+
async put(key: string, value: ReadonlyJSONValue) {
11+
const jsonValueString = JSON.stringify(value);
12+
await this._tx.upsert(key, jsonValueString);
3413
}
3514

36-
release() {
37-
this._tx.commit();
38-
this._closed = true;
15+
async del(key: string) {
16+
await this._tx.delete(key);
3917
}
4018

41-
get closed() {
42-
return this._closed;
19+
async commit() {
20+
// Do nothing and wait for release.
4321
}
4422
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ __metadata:
25282528
"@braden1996/tsconfig": ^0.0.1
25292529
"@react-native-replicache/example-client-shared": 0.0.0
25302530
"@react-native-replicache/example-shared": 0.0.0
2531-
"@react-native-replicache/react-native-quick-sqlite": 0.0.2
2531+
"@react-native-replicache/react-native-quick-sqlite": 0.0.3
25322532
"@types/react": ^18.0.28
25332533
"@types/react-native": ~0.71.2
25342534
"@types/react-native__assets": ^1.0.0
@@ -2624,7 +2624,7 @@ __metadata:
26242624
languageName: unknown
26252625
linkType: soft
26262626

2627-
"@react-native-replicache/react-native-quick-sqlite@0.0.2, @react-native-replicache/react-native-quick-sqlite@workspace:packages/react-native-quick-sqlite":
2627+
"@react-native-replicache/react-native-quick-sqlite@0.0.3, @react-native-replicache/react-native-quick-sqlite@workspace:packages/react-native-quick-sqlite":
26282628
version: 0.0.0-use.local
26292629
resolution: "@react-native-replicache/react-native-quick-sqlite@workspace:packages/react-native-quick-sqlite"
26302630
dependencies:

0 commit comments

Comments
 (0)