-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify ExperimentalCreateKVStore Write class.
- Loading branch information
1 parent
2f5b263
commit 761153f
Showing
6 changed files
with
19 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
62 changes: 0 additions & 62 deletions
62
packages/react-native-quick-sqlite/src/replicache-quick-sqlite-write-impl-base.ts
This file was deleted.
Oops, something went wrong.
50 changes: 14 additions & 36 deletions
50
packages/react-native-quick-sqlite/src/replicache-quick-sqlite-write-impl.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,22 @@ | ||
import { ReplicacheQuickSQLiteReadImpl } from "./replicache-quick-sqlite-read-impl"; | ||
import { ReplicacheQuickSQLiteTransaction } from "./replicache-quick-sqlite-transaction"; | ||
import { | ||
deleteSentinel, | ||
ReplicacheQuickSQLiteWriteImplBase, | ||
} from "./replicache-quick-sqlite-write-impl-base"; | ||
|
||
export class ReplicacheQuickSQLiteWriteImpl extends ReplicacheQuickSQLiteWriteImplBase { | ||
private readonly _tx: ReplicacheQuickSQLiteTransaction; | ||
private _closed = false; | ||
|
||
constructor(tx: ReplicacheQuickSQLiteTransaction) { | ||
super(new ReplicacheQuickSQLiteReadImpl(tx)); | ||
this._tx = tx; | ||
} | ||
import { ExperimentalCreateKVStore, ReadonlyJSONValue } from "replicache"; | ||
|
||
async commit() { | ||
if (this._pending.size === 0) { | ||
return; | ||
} | ||
|
||
await Promise.all( | ||
[...this._pending.entries()].map(async ([key, value]) => { | ||
if (value === deleteSentinel) { | ||
await this._tx.delete(key); | ||
} else { | ||
const jsonValueString = JSON.stringify(value); | ||
await this._tx.upsert(key, jsonValueString); | ||
} | ||
}) | ||
); | ||
import { ReplicacheQuickSQLiteReadImpl } from "./replicache-quick-sqlite-read-impl"; | ||
|
||
this._pending.clear(); | ||
export class ReplicacheQuickSQLiteWriteImpl | ||
extends ReplicacheQuickSQLiteReadImpl | ||
implements | ||
Awaited<ReturnType<ReturnType<ExperimentalCreateKVStore>["write"]>> | ||
{ | ||
async put(key: string, value: ReadonlyJSONValue) { | ||
const jsonValueString = JSON.stringify(value); | ||
await this._tx.upsert(key, jsonValueString); | ||
} | ||
|
||
release() { | ||
this._tx.commit(); | ||
this._closed = true; | ||
async del(key: string) { | ||
await this._tx.delete(key); | ||
} | ||
|
||
get closed() { | ||
return this._closed; | ||
async commit() { | ||
// Do nothing and wait for release. | ||
} | ||
} |
This file contains 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