This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
colorsById.js
65 lines (58 loc) · 1.88 KB
/
colorsById.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
"use strict";
var Model = require("falcor").Model,
$error = Model.error,
$atom = Model.atom,
$ref = Model.ref,
chunk = require("./lib/chunk"),
map = require("./lib/map-ids"),
fields = require("./lib/fields");
module.exports = [ {
route : "colorsById[{integers:ids}].id",
get : function(pathset) {
return pathset.ids.map(function(id) {
return {
path : [ pathset[0], id, pathset[2] ],
value : $atom(id)
};
});
},
}, {
route : "colorsById[{integers:ids}].item",
get : function(pathset) {
return chunk("https://api.guildwars2.com/v2/colors?ids=", pathset.ids)
.then(map)
.then(function(map) {
return pathset.ids.map(function(id) {
if(!map[id]) {
return {
path : [ pathset[0], id ],
value : $error("Unknown color")
};
}
return {
path : [ pathset[0], id, pathset[2] ],
value : $ref([ "itemsById", map[id].item ])
};
});
});
}
}, {
route : "colorsById[{integers:ids}][{keys:fields}]",
get : function(pathset) {
return chunk("https://api.guildwars2.com/v2/colors?ids=", pathset.ids)
.then(map)
.then(function(map) {
var paths = [];
pathset.ids.forEach(function(id) {
if(!map[id]) {
return paths.push({
path : [ pathset[0], id ],
value : $error("Unknown color")
});
}
fields(paths, pathset.fields, [ pathset[0], id ], map[id]);
});
return paths;
});
}
} ];