-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
55 lines (55 loc) · 1.3 KB
/
script.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
const JSON_PATH = '../../comment.json'
const LIMIT = 30
const app = Vue.createApp({
setup() {
document.body.removeAttribute('hidden')
},
data () {
return {
comments: []
}
},
methods: {
getClassName(comment) {
if (comment.commentIndex % 2 === 0) {
return 'comment even'
}
return 'comment odd'
},
getStyle(comment) {
return OneSDK.getCommentStyle(comment)
}
},
mounted () {
let cache = new Map()
commentIndex = 0
OneSDK.setup({
jsonPath: JSON_PATH,
commentLimit: LIMIT
})
OneSDK.subscribe({
action: 'comments',
callback: (comments) => {
const newCache = new Map()
comments.forEach(comment => {
const index = cache.get(comment.data.id)
if (isNaN(index)) {
comment.commentIndex = commentIndex
newCache.set(comment.data.id, commentIndex)
++commentIndex
} else {
comment.commentIndex = index
newCache.set(comment.data.id, index)
}
checkBiribiriComment(comment)
})
cache = newCache
this.comments = comments
}
})
OneSDK.connect()
},
})
OneSDK.ready().then(() => {
app.mount("#container");
})