-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournalPresenter.ts
34 lines (29 loc) · 1.09 KB
/
journalPresenter.ts
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
import { JournalRepository, JournalState } from "./journalRepository.ts";
import { ClientStorageRepository } from "./clientStorageRepository.ts";
import { JournalViewModel } from "./journalViewModel.ts";
export class JournalPresenter {
private vm: JournalViewModel;
private readonly journalRepo: JournalRepository;
private readonly clientRepo: ClientStorageRepository;
constructor(
journalRepo: JournalRepository,
clientRepo: ClientStorageRepository
) {
this.journalRepo = journalRepo;
this.clientRepo = clientRepo;
this.vm = new JournalViewModel({ journals: [], pendingDeletion: null, showConfirmationModal: false });
}
async getJournals(componentCb: (vm: JournalViewModel) => void) {
await this.journalRepo.loadJournals((journalState) => {
this.buildViewModel(journalState);
// Map over the journalState and return a new view model.
componentCb(this.vm);
});
}
async loadFavoriteJournals() {
return await this.clientRepo.getAll();
}
private buildViewModel(journalState: JournalState) {
this.vm = new JournalViewModel(journalState);
}
}