-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
50 lines (43 loc) · 980 Bytes
/
store.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
'use strict'
let validData = ($, callback) => {
$.getUserSession('params').then(data => {
if (Object.isEmpty(data)) {
// default params
data.score = 0
data.category = Object.keys(categories)[0]
data.question = configs[data.category].question
data.shown_images = []
$.setUserSession('params', data).then(() => {
callback(false)
})
}
else
callback(true)
})
}
let getData = ($, callback) => {
$.getUserSession('params').then(data => {
if (!Object.isEmpty(data))
callback(data)
else
throw new Error('data is empty!')
})
}
let setData = ($, params, callback) => {
$.getUserSession('params').then(data => {
if (!Object.isEmpty(data)) {
let properties = Object.keys(params)
for (let property of properties)
data[property] = params[property]
$.setUserSession('params', data).then(() => {
callback(data)
})
} else
throw new Error('data is empty!')
})
}
module.exports = {
validData,
getData,
setData
}