Skip to content

Commit be18f1e

Browse files
committed
wip
1 parent 59d3938 commit be18f1e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/observer.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Adapter } from 'lowdb'
2+
3+
// Lowdb adapter to observe read/write events
4+
export class Observer<T> {
5+
#adapter
6+
7+
onReadStart = function () {
8+
return
9+
}
10+
onReadEnd = function () {
11+
return
12+
}
13+
onWriteStart = function () {
14+
return
15+
}
16+
onWriteEnd = function () {
17+
return
18+
}
19+
20+
constructor(adapter: Adapter<T>) {
21+
this.#adapter = adapter
22+
}
23+
24+
async read() {
25+
this.onReadStart()
26+
const data = await this.#adapter.read()
27+
this.onReadEnd()
28+
return data
29+
}
30+
31+
async write(arg: T) {
32+
this.onWriteStart()
33+
await this.#adapter.write(arg)
34+
this.onWriteEnd()
35+
}
36+
}

views/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
</main>
3636
</body>
3737

38-
</html>
38+
</html>

0 commit comments

Comments
 (0)