-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.js
More file actions
56 lines (48 loc) · 1.15 KB
/
event.js
File metadata and controls
56 lines (48 loc) · 1.15 KB
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
48
49
50
51
52
53
54
55
56
'use strict';
/////////////////////////////////////////////////////////////////////////////
// EVENTS EMITTER TEST
//
// Copyright Scale Computing 2015
// DO NOT DISTRIBUTE OR REPRODUCE ONLINE IN ANY FORM
/////////////////////////////////////////////////////////////////////////////
/**
* Fix the following code and make the accompanying unit tests in
* event.mocha.js pass.
*/
module.exports = function changeEmitterFactory() {
var events = require('events');
var changeEmitter = new events.EventEmitter();
var data;
/**
* Emit a change event if the data is changed
* param newData the data that we're updating to
*
* private
*/
function emitOnDiff(oldData) {
if (oldData !== data) {
changeEmitter.emit('change', data);
}
}
/**
* Set the data
* param newData the data that we're updating to
*
* public
*/
changeEmitter.setData = function setData(newData) {
var oldData = data;
data = newData;
emitOnDiff(oldData);
// set the data here
};
/**
* Get the current data
*
* public
*/
changeEmitter.getData = function getData() {
return data;
};
return changeEmitter;
};