-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaffold.js
More file actions
49 lines (39 loc) · 1.13 KB
/
scaffold.js
File metadata and controls
49 lines (39 loc) · 1.13 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
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
([], function () {
'use strict';
// service scaffolding
function defaultOptIn (options) {
return !options.transport && (!options.method || options.method.toUpperCase() == 'GET');
}
var names = ['theDefault', 'attach', 'detach', 'optIn'];
return function (io, name, priority, callback) {
var service = io[name] = io[name] || {};
service.isActive = false;
var methods = [defaultOptIn, attach, detach, optIn];
names.forEach(function (name, index) {
if (!(name in service)) {
service[name] = methods[index];
}
});
return io;
function attach () {
io.attach({
name: name,
priority: priority,
callback: callback
});
io[name].isActive = true;
}
function detach () {
io.detach(name);
io[name].isActive = false;
}
function optIn (options) {
if (name in options) {
return options[name];
}
var optIn = service.theDefault;
return typeof optIn == 'function' ? optIn(options) : optIn;
}
};
});