File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 35
35
</ main >
36
36
</ body >
37
37
38
- </ html >
38
+ </ html >
You can’t perform that action at this time.
0 commit comments