-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMessageStore.ts
More file actions
38 lines (34 loc) · 844 Bytes
/
MessageStore.ts
File metadata and controls
38 lines (34 loc) · 844 Bytes
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
import IStoreWriter from "./IStoreWriter";
import IStoreReader from "./IStoreReader";
export default class MessageStore {
writer: IStoreWriter;
reader: IStoreReader;
constructor(writer: IStoreWriter,reader: IStoreReader) {
if(writer === null) {
throw new Error("writer argument cannot be null")
}
if(reader === null) {
throw new Error("reader argument cannot be null")
}
this.writer = writer;
this.reader = reader;
}
/**
*
* @param id the id of the message to save
* @param message the text message to write to storage
*
*/
public save(id: number, message: string) {
this.writer.save(id, message);
}
/**
*
* @param id the id of the message to read
* @returns message string
*
*/
public read(id: number): string {
return this.reader.read(id);
}
}