-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
logger.js
90 lines (84 loc) · 1.99 KB
/
logger.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
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint no-console: "off" */
const defaultLogger = {
hit: () => {
console.log(`Hit scroll threshold`);
},
top: () => {
console.log(`Hit top scroll threshold`);
},
binded: () => {
console.log(`Binded event handlers`);
},
unbinded: () => {
console.log(`Unbinded event handlers`);
},
// scrolled: (event) => {
// console.log('Scrolled');
// },
// resized: (event) => {
// console.log('Resized');
// },
next: (event) => {
console.log(`Next page triggered [pageIndex=${event.pageIndex}]`);
},
nexted: (event) => {
console.log(`Next page completed [pageIndex=${event.pageIndex}]`);
},
prev: (event) => {
console.log(`Previous page triggered [pageIndex=${event.pageIndex}]`);
},
preved: (event) => {
console.log(`Previous page completed [pageIndex=${event.pageIndex}]`);
},
load: (event) => {
console.log(`Start loading ${event.url}`);
},
loaded: () => {
console.log(`Finished loading`);
},
append: () => {
console.log(`Start appending items`);
},
appended: (event) => {
console.log(`Finished appending ${event.items.length} item(s)`);
},
prepend: () => {
console.log(`Start prepending items`);
},
prepended: (event) => {
console.log(`Finished prepending ${event.items.length} item(s)`);
},
last: () => {
console.log(`No more pages left to load`);
},
first: () => {
console.log(`Reached first page`);
},
page: (event) => {
console.log(`Page changed [pageIndex=${event.pageIndex}]`);
},
prefill: (event) => {
console.log(`Start prefilling`);
},
prefilled: (event) => {
console.log(`Finished prefilling`);
},
};
function expand(options) {
if (options === true) {
options = defaultLogger
}
return options;
}
export default class Logger {
constructor(ias, options) {
// no logger wanted
if (options === false) {
return;
}
let logger = expand(options);
Object.keys(logger).forEach((key) => {
ias.on(key, logger[key]);
});
}
}