-
-
Notifications
You must be signed in to change notification settings - Fork 634
/
index.js
58 lines (51 loc) · 1.45 KB
/
index.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
import * as R from 'ramda';
import { constants } from './lib/constants.js';
import memoizee from 'memoizee';
import appMethod from './lib/app.js';
import list from './lib/list.js';
import search from './lib/search.js';
import suggest from './lib/suggest.js';
import developer from './lib/developer.js';
import reviews from './lib/reviews.js';
import similar from './lib/similar.js';
import permissions from './lib/permissions.js';
import datasafety from './lib/datasafety.js';
import categories from './lib/categories.js';
const methods = {
app: appMethod,
list,
search: R.partial(search, [appMethod]),
suggest,
developer,
reviews,
similar,
permissions,
datasafety,
categories
};
function memoized (opts) {
const cacheOpts = Object.assign({
primitive: true,
normalizer: JSON.stringify,
maxAge: 1000 * 60 * 5, // cache for 5 minutes
max: 1000 // save up to 1k results to avoid memory issues
}, opts);
// need to rebuild the methods so they all share the same memoized appMethod
const doMemoize = (fn) => memoizee(fn, cacheOpts);
const mAppMethod = memoizee(appMethod, cacheOpts);
const otherMethods = {
list,
search: R.partial(search, [mAppMethod]),
suggest,
developer,
reviews,
similar,
permissions,
datasafety,
categories
};
return Object.assign({ app: mAppMethod },
constants,
R.map(doMemoize, otherMethods));
}
export default Object.assign({ memoized }, constants, methods);