forked from apiacademy/ndcoslo2015
-
Notifications
You must be signed in to change notification settings - Fork 3
/
components.js
77 lines (64 loc) · 1.67 KB
/
components.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
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************
* task service implementation
* business component (server)
* May 2015
* Mike Amundsen (@mamund)
* Soundtrack : Complete Collection : B.B. King (2008)
*******************************************************/
// matches storage calls w/ middleware domain-specific verbs
// access stored data
var storage = require('./storage.js');
exports.todo = function(action, args1, args2, args3) {
var object, rtn;
object = 'todo';
rtn = null;
switch (action) {
case 'list':
rtn = loadList(storage(object, 'list'), object);
break;
case 'read':
rtn = loadList(storage(object, 'item', args1), object);
break;
case 'filter':
rtn = loadList(storage(object, 'filter', args1), object);
break;
case 'add':
rtn = loadList(storage(object, 'add', args1), object);
break;
case 'update':
rtn = loadList(storage(object, 'update', args1, args2, args3), object);
break;
case 'remove':
rtn = loadList(storage(object, 'remove', args1), object);
break;
default:
rtn = null;
}
return rtn;
}
function loadList(elm, name) {
var coll, list, i, x;
if (Array.isArray(elm) === false) {
coll = [];
coll.push(elm);
} else {
coll = elm;
}
list = [];
for (i = 0, x = coll.length; i < x; i++) {
list.push(coll[i]);
}
return list;
}
// TK: is this in use?
function getId(data) {
var i, x, rtn;
for (i = 0, x = data.length; i < x; i++) {
if (data[i].name === 'id') {
rtn = data[i].value;
break;
}
}
return rtn;
}
// EOF