@jetthai/cuora 1.0.179 → 1.0.180
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/machine/game_favorite_v2.js +114 -0
- package/src/machine/game_v2.js +2 -87
- package/src/machine/index.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.180](https://github.com/jetthai/cuora-module/compare/v1.0.179...v1.0.180) (2022-09-28)
|
|
6
|
+
|
|
5
7
|
### [1.0.179](https://github.com/jetthai/cuora-module/compare/v1.0.178...v1.0.179) (2022-09-26)
|
|
6
8
|
|
|
7
9
|
### [1.0.178](https://github.com/jetthai/cuora-module/compare/v1.0.177...v1.0.178) (2022-09-26)
|
package/package.json
CHANGED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import api from '../api/game.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'favorite',
|
|
8
|
+
type: 'parallel',
|
|
9
|
+
context: {
|
|
10
|
+
list: [],
|
|
11
|
+
},
|
|
12
|
+
states: {
|
|
13
|
+
fetching: {
|
|
14
|
+
invoke: {
|
|
15
|
+
src: 'fetchList',
|
|
16
|
+
onDone: {
|
|
17
|
+
actions: 'setList',
|
|
18
|
+
},
|
|
19
|
+
onError: {
|
|
20
|
+
actions: assign({ list: [] }),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
adding: {
|
|
25
|
+
initial: 'disable',
|
|
26
|
+
states: {
|
|
27
|
+
disable: {},
|
|
28
|
+
enable: {
|
|
29
|
+
invoke: {
|
|
30
|
+
src: 'add',
|
|
31
|
+
onDone: {},
|
|
32
|
+
onError: {
|
|
33
|
+
actions: 'removeFromList',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
removing: {
|
|
40
|
+
initial: 'disable',
|
|
41
|
+
states: {
|
|
42
|
+
disable: {},
|
|
43
|
+
enable: {
|
|
44
|
+
invoke: {
|
|
45
|
+
src: 'remove',
|
|
46
|
+
onDone: {},
|
|
47
|
+
onError: {
|
|
48
|
+
actions: 'addToList',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
on: {
|
|
56
|
+
ADD: {
|
|
57
|
+
target: 'adding.enable',
|
|
58
|
+
actions: 'addToList',
|
|
59
|
+
cond: 'isNotExist',
|
|
60
|
+
},
|
|
61
|
+
REMOVE: {
|
|
62
|
+
target: 'removing.enable',
|
|
63
|
+
actions: 'removeFromList',
|
|
64
|
+
cond: 'isExist',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
actions: {
|
|
70
|
+
setList: assign((context, event) => {
|
|
71
|
+
return {
|
|
72
|
+
list: event.data,
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
addToList: assign((context, event) => {
|
|
76
|
+
return {
|
|
77
|
+
list: [...context.list, event.data],
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
removeFromList: assign((context, event) => {
|
|
81
|
+
return {
|
|
82
|
+
list: context.list.filter((item) => item.gameCode !== event.data.gameCode),
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
guards: {
|
|
87
|
+
isExist: (context, event) => context.list.some((item) => item.gameCode === event.data.gameCode),
|
|
88
|
+
isNotExist: (context, event) => !context.list.some((item) => item.gameCode === event.data.gameCode)
|
|
89
|
+
},
|
|
90
|
+
services: {
|
|
91
|
+
add: async (context, event) => {
|
|
92
|
+
try {
|
|
93
|
+
await request.send(api.addListFavorite(event.data.gameCode))
|
|
94
|
+
return event.data
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw event.data
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
remove: async (context, event) => {
|
|
100
|
+
try {
|
|
101
|
+
await request.send(api.removeListFavorite(event.data.gameCode))
|
|
102
|
+
return event.data
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw event.data
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
fetchList: async (context, event) => {
|
|
108
|
+
const { data } = await request.send(api.getListMyFavorite())
|
|
109
|
+
return data
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
}
|
package/src/machine/game_v2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import api from '../api/game.js'
|
|
3
3
|
import UAParser from 'ua-parser-js'
|
|
4
|
-
import {
|
|
4
|
+
import { GAME_SEARCH } from '../util/constant.js'
|
|
5
5
|
|
|
6
6
|
export default function (request) {
|
|
7
7
|
return createMachine(
|
|
@@ -17,7 +17,6 @@ export default function (request) {
|
|
|
17
17
|
parentCategoryId: null,
|
|
18
18
|
totalPage: 1,
|
|
19
19
|
},
|
|
20
|
-
favoriteList: [],
|
|
21
20
|
// play params
|
|
22
21
|
game: {
|
|
23
22
|
providerId: null,
|
|
@@ -52,16 +51,6 @@ export default function (request) {
|
|
|
52
51
|
target: 'connecting',
|
|
53
52
|
actions: ['setGameInfo', 'setLang'],
|
|
54
53
|
},
|
|
55
|
-
ADD_FAVORITE: {
|
|
56
|
-
target: 'adding',
|
|
57
|
-
cond: 'isNotFavorite',
|
|
58
|
-
actions: 'addToFavoriteList',
|
|
59
|
-
},
|
|
60
|
-
REMOVE_FAVORITE: {
|
|
61
|
-
target: 'removing',
|
|
62
|
-
cond: 'isFavorite',
|
|
63
|
-
actions: 'removeFromFavoriteList',
|
|
64
|
-
},
|
|
65
54
|
},
|
|
66
55
|
},
|
|
67
56
|
loading: {
|
|
@@ -106,47 +95,11 @@ export default function (request) {
|
|
|
106
95
|
},
|
|
107
96
|
},
|
|
108
97
|
},
|
|
109
|
-
adding: {
|
|
110
|
-
invoke: {
|
|
111
|
-
src: 'addFavorite',
|
|
112
|
-
onDone: {
|
|
113
|
-
target: 'idle',
|
|
114
|
-
},
|
|
115
|
-
onError: {
|
|
116
|
-
target: 'idle',
|
|
117
|
-
actions: 'removeFromFavoriteList',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
removing: {
|
|
122
|
-
invoke: {
|
|
123
|
-
src: 'removeFavorite',
|
|
124
|
-
onDone: {
|
|
125
|
-
target: 'idle',
|
|
126
|
-
},
|
|
127
|
-
onError: {
|
|
128
|
-
target: 'idle',
|
|
129
|
-
actions: 'addToFavoriteList',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
98
|
},
|
|
134
99
|
},
|
|
135
100
|
timer: {
|
|
136
|
-
initial: '
|
|
101
|
+
initial: 'pending',
|
|
137
102
|
states: {
|
|
138
|
-
favorite: {
|
|
139
|
-
invoke: {
|
|
140
|
-
src: 'getFavorite',
|
|
141
|
-
onDone: {
|
|
142
|
-
target: 'pending',
|
|
143
|
-
actions: 'setFavoriteList',
|
|
144
|
-
},
|
|
145
|
-
onError: {
|
|
146
|
-
target: 'pending',
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
103
|
pending: {
|
|
151
104
|
after: {
|
|
152
105
|
20000: [
|
|
@@ -260,7 +213,6 @@ export default function (request) {
|
|
|
260
213
|
} else {
|
|
261
214
|
const { data, ...rest } = event.data
|
|
262
215
|
return {
|
|
263
|
-
favoriteList: room.categoryId === MY_FAVORITE ? data : favoriteList,
|
|
264
216
|
content: {
|
|
265
217
|
...context.content,
|
|
266
218
|
...rest,
|
|
@@ -270,11 +222,9 @@ export default function (request) {
|
|
|
270
222
|
}
|
|
271
223
|
}),
|
|
272
224
|
swapContent: assign((context, event) => {
|
|
273
|
-
const { room, favoriteList } = context
|
|
274
225
|
const item = event.data
|
|
275
226
|
if (item.data?.length) {
|
|
276
227
|
return {
|
|
277
|
-
favoriteList: room.categoryId === MY_FAVORITE ? event.data.data : favoriteList,
|
|
278
228
|
content: event.data,
|
|
279
229
|
}
|
|
280
230
|
}
|
|
@@ -300,36 +250,19 @@ export default function (request) {
|
|
|
300
250
|
const lang = event.data.locale.replace('-', '_')
|
|
301
251
|
return { lang }
|
|
302
252
|
}),
|
|
303
|
-
addToFavoriteList: assign((context, event) => {
|
|
304
|
-
return {
|
|
305
|
-
favoriteList: [...context.favoriteList, event.data],
|
|
306
|
-
}
|
|
307
|
-
}),
|
|
308
|
-
removeFromFavoriteList: assign((context, event) => {
|
|
309
|
-
return {
|
|
310
|
-
favoriteList: context.favoriteList.filter((item) => item.gameCode !== event.data.gameCode),
|
|
311
|
-
}
|
|
312
|
-
}),
|
|
313
253
|
...oldActions
|
|
314
254
|
},
|
|
315
255
|
guards: {
|
|
316
256
|
isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
|
|
317
257
|
hasNext: (context, event) => context.index < context?.content?.totalPage - 1,
|
|
318
258
|
hasRoom: (context, event) => context.room?.categoryId,
|
|
319
|
-
isFavorite: (context, event) => context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
320
|
-
isNotFavorite: (context, event) => !context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
321
259
|
...oldGuards
|
|
322
260
|
},
|
|
323
261
|
services: {
|
|
324
|
-
getFavorite: async (context, event) => {
|
|
325
|
-
return await request.send(api.getListMyFavorite())
|
|
326
|
-
},
|
|
327
262
|
getPageContent: async (context, event) => {
|
|
328
263
|
const { room, index } = context
|
|
329
264
|
if (room.categoryId === GAME_SEARCH) {
|
|
330
265
|
return
|
|
331
|
-
} else if (room.categoryId === MY_FAVORITE) {
|
|
332
|
-
return await request.send(api.getListMyFavorite())
|
|
333
266
|
} else {
|
|
334
267
|
return await request.send(api.getListCategory({ categoryId: room.categoryId, index }))
|
|
335
268
|
}
|
|
@@ -338,8 +271,6 @@ export default function (request) {
|
|
|
338
271
|
const { room, content, index } = context
|
|
339
272
|
if (room.categoryId === GAME_SEARCH) {
|
|
340
273
|
return
|
|
341
|
-
} else if (room.categoryId === MY_FAVORITE) {
|
|
342
|
-
// return await request.send(api.getListMyFavorite({ timestamp: content.timestamp }))
|
|
343
274
|
} else {
|
|
344
275
|
return await request.send(
|
|
345
276
|
api.getListCategoryByRange({
|
|
@@ -371,22 +302,6 @@ export default function (request) {
|
|
|
371
302
|
const provider_id = context.game.providerId
|
|
372
303
|
return await request.send(api.logoutGame({ uid_site, provider_id }))
|
|
373
304
|
},
|
|
374
|
-
addFavorite: async (context, event) => {
|
|
375
|
-
try {
|
|
376
|
-
await request.send(api.addListFavorite(event.data.gameCode))
|
|
377
|
-
return event.data
|
|
378
|
-
} catch (error) {
|
|
379
|
-
throw event.data
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
removeFavorite: async (context, event) => {
|
|
383
|
-
try {
|
|
384
|
-
await request.send(api.removeListFavorite(event.data.gameCode))
|
|
385
|
-
return event.data
|
|
386
|
-
} catch (error) {
|
|
387
|
-
throw event.data
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
305
|
...oldServices(request)
|
|
391
306
|
},
|
|
392
307
|
}
|
package/src/machine/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import error from './error.js'
|
|
|
7
7
|
import game from './game.js'
|
|
8
8
|
import game_v2 from './game_v2.js'
|
|
9
9
|
import game_favorite from './game_favorite.js'
|
|
10
|
+
import game_favorite_v2 from './game_favorite_v2.js'
|
|
10
11
|
import game_search from './game_search.js'
|
|
11
12
|
import game_hot_new from './game_hot_new.js'
|
|
12
13
|
import inbox from './inbox.js'
|
|
@@ -42,6 +43,7 @@ export default {
|
|
|
42
43
|
game,
|
|
43
44
|
game_v2,
|
|
44
45
|
game_favorite,
|
|
46
|
+
game_favorite_v2,
|
|
45
47
|
game_search,
|
|
46
48
|
game_hot_new,
|
|
47
49
|
inbox,
|