-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
32 lines (25 loc) · 804 Bytes
/
main.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
'use strict'
let Task = require('../fixtures/Task')
let ObserverList = require('./ObserverList')
// Observable task Inherit Task for observers include
let ObservableTask = function (data) {
Task.call(this, data)
this.observers = new ObserverList()
}
ObservableTask.prototype.addObserver = function (observer) {
this.observers.add(observer)
}
ObservableTask.prototype.removeObserver = function (observer) {
this.observers.removeAt(this.observers.indexOf(observer, 0))
}
ObservableTask.prototype.notify = function (context) {
let observersCount = this.observers.count()
for (let i = 0; i < observersCount; i++) {
this.observers.get(i)(context)
}
}
ObservableTask.prototype.save = function () {
Task.prototype.save.call(this)
this.notify(this)
}
module.exports = ObservableTask