-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathStoreLogger.ts
More file actions
61 lines (50 loc) · 1.35 KB
/
StoreLogger.ts
File metadata and controls
61 lines (50 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import IStoreWriter from "./IStoreWriter"
import IStoreReader from "./IStoreReader";
export default class StoreLogger implements IStoreWriter, IStoreReader {
writer: IStoreWriter
reader: IStoreReader
constructor(_writer: IStoreWriter, _reader: IStoreReader){
this.writer = _writer;
this.reader = _reader;
}
public read(id: number): string {
this.reading(id)
var retValue = this.reader.read(id);
if(retValue === undefined){
this.didNotFind(id)
} else {
this.returning(id)
}
return retValue;
}
public save(id: number, message: string): void {
this.saving(id);
try {
this.writer.save(id, message);
} catch (err) {
this.errorSaving(id)
}
this.saved(id);
}
public saving(id: number): void {
console.log(`Saving message ${id}.`)
}
public saved(id: number): void {
console.info(`Saved message ${id}.`)
}
public reading(id: number): void {
console.debug(`Reading message ${id}`)
}
public didNotFind(id: number): void {
console.debug(`No message ${id} found.`)
}
public missingFromCache(id: number): void {
console.debug(`Message ${id} missing from cache.`)
}
public returning(id: number): void {
console.debug(`Returning message ${id}.`)
}
public errorSaving(id: number): void {
console.error(`Error saving message ${id}.`)
}
}