-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFacade.ts
More file actions
47 lines (39 loc) · 897 Bytes
/
Copy pathFacade.ts
File metadata and controls
47 lines (39 loc) · 897 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
39
40
41
42
43
44
45
46
47
class Notify {
send(template: string, to: string) {
console.log(`Отправляю ${template}: ${to}`)
}
}
class Log {
log(message: string) {
console.log(message)
}
}
class Template {
private templates = [
{name: 'other', template: `<h1>Шаблон<h1>`}
]
getByName(name: string) {
return this.templates.find(t => t.name === name)
}
}
class NotificationFacade {
private notify: Notify;
private log: Log;
private template: Template;
constructor() {
this.notify = new Notify()
this.log = new Log()
this.template = new Template()
}
send(to: string, templateName: string) {
const data = this.template.getByName(templateName);
if (!data) {
this.log.log('Не найден шаблон')
return;
}
this.notify.send(data.template, to)
this.log.log('Шаблон отправлен')
}
}
const s = new NotificationFacade()
s.send('a@a.ua', 'other')