-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacade.js
46 lines (38 loc) · 827 Bytes
/
facade.js
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
'use strict'
/**
* Difference between Facade and Decorator is
* Facade not ADD new functionalities
*/
function Task (data) {
this.name = data.name
this.completed = false
this.status = 'unsaved'
}
let TaskService = (function () {
function complete (task) {
task.completed = true
}
function save (task) {
task.status = 'saved'
}
return {
complete: complete,
save: save
}
}())
let TaskServiceWrapper = (function () {
function completeAndSave (task) {
TaskService.complete(task)
TaskService.save(task)
if (task.completed === true && task.status === 'saved') {
return true
} else {
return false
}
}
return {
completeAndSave: completeAndSave
}
}())
module.exports.TaskServiceWrapper = TaskServiceWrapper.completeAndSave
module.exports.Task = Task