-
Notifications
You must be signed in to change notification settings - Fork 22
/
connectors.js
59 lines (55 loc) · 1.13 KB
/
connectors.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
import _ from 'lodash';
// Fake word generator
import faker from 'faker';
// Let's generate some tags
var id = 0;
var tags = [];
for (let i = 0; i < 42; i++) {
if(Math.random() < .5) {
addTag('City', faker.address.city());
} else {
addTag('Company', faker.company.companyName());
}
}
function addTag(type, label) {
return new Promise(resolve => {
setTimeout(() => {
let t = {
id: id++,
label,
type,
};
tags.push(t);
resolve(t);
}, 2000);
});
}
function fakeDelay (cb) {
return new Promise(resolve => {
setTimeout(() => {
resolve(cb())
}, 2000)
})
}
export default {
getTags(type) {
return fakeDelay(() => _.filter(tags, tag => tag.type === type))
},
getTagsPage(page, pageSize) {
return fakeDelay(() => {
const start = page * pageSize;
const end = start + pageSize;
return {
tags: tags.slice(start, end),
hasMore: end < tags.length,
};
})
},
getRandomTag() {
return tags[Math.round(Math.random()*(tags.length - 1))];
},
getLastTag() {
return tags[tags.length - 1];
},
addTag,
};