-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleeper.js
66 lines (63 loc) · 1.44 KB
/
sleeper.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var sleeper = ( function () {
var isSleeperOn = false,
_on = function () {
isSleeperOn = true;
},
_off = function () {
isSleeperOn = false;
},
streams = {
'CONSOLE': console
},
selectedStream = streams[ 'CONSOLE' ],
_addStream = function ( streamName, streamObject ) {
streams[streamName] = streamObject;
},
_removeStream = function ( streamName ) {
if ( streams[ streamName ] ) {
delete streams[ streamName ];
}
},
_setStream = function ( streamName ) {
if ( streams[ streamName ] ) {
selectedStream = streams[ streamName ];
} else {
if ( streamName ) {
throw new Error( "setStream(): a stream with name " + streamName + " was not found.");
} else {
throw new Error( "setStream(): first argument must be a stream name" );
}
}
},
_log = function ( args ) {
if ( isSleeperOn && selectedStream.log ) {
selectedStream.log( args );
}
},
_dir = function ( args ) {
if ( isSleeperOn && selectedStream.dir ) {
selectedStream.dir( args );
}
},
_error = function ( args ) {
if ( isSleeperOn && selectedStream.error ) {
selectedStream.error( args );
}
},
_warn = function ( args ) {
if ( isSleeperOn && selectedStream.warn ) {
selectedStream.warn( args );
}
};
return {
on: _on,
off: _off,
addStream: _addStream,
removeStream: _removeStream,
setStream: _setStream,
log: _log,
dir: _dir,
error: _error,
warn: _warn
};
} ) ();