@jetthai/cuora 1.0.178 → 1.0.179
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_v2.js +126 -12
- package/src/machine/side_v2.js +5 -2
- package/src/util/constant.js +2 -1
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.179](https://github.com/jetthai/cuora-module/compare/v1.0.178...v1.0.179) (2022-09-26)
|
|
6
|
+
|
|
5
7
|
### [1.0.178](https://github.com/jetthai/cuora-module/compare/v1.0.177...v1.0.178) (2022-09-26)
|
|
6
8
|
|
|
7
9
|
### [1.0.177](https://github.com/jetthai/cuora-module/compare/v1.0.168-1...v1.0.177) (2022-09-23)
|
package/package.json
CHANGED
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 { MY_FAVORITE } from '../util/constant.js'
|
|
4
|
+
import { MY_FAVORITE, GAME_SEARCH } from '../util/constant.js'
|
|
5
5
|
|
|
6
6
|
export default function (request) {
|
|
7
7
|
return createMachine(
|
|
@@ -29,6 +29,7 @@ export default function (request) {
|
|
|
29
29
|
lang: 'en_US',
|
|
30
30
|
isMobile: new UAParser().getResult().device.type,
|
|
31
31
|
gameURL: null,
|
|
32
|
+
...oldContext
|
|
32
33
|
},
|
|
33
34
|
states: {
|
|
34
35
|
flow: {
|
|
@@ -173,6 +174,60 @@ export default function (request) {
|
|
|
173
174
|
},
|
|
174
175
|
},
|
|
175
176
|
},
|
|
177
|
+
oldTimer: {
|
|
178
|
+
initial: 'fetchingGameSHA',
|
|
179
|
+
states: {
|
|
180
|
+
fetchingGameSHA: {
|
|
181
|
+
invoke: {
|
|
182
|
+
src: 'fetchGameSHA',
|
|
183
|
+
onDone: {
|
|
184
|
+
target: 'checking',
|
|
185
|
+
actions: 'setGameSHA',
|
|
186
|
+
},
|
|
187
|
+
onError: {
|
|
188
|
+
target: 'pending',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
checking: {
|
|
193
|
+
always: [
|
|
194
|
+
{ target: 'updatingStatus', cond: 'isStatusChanged' },
|
|
195
|
+
{ target: 'pending' },
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
updatingStatus: {
|
|
199
|
+
invoke: {
|
|
200
|
+
src: 'fetchStatus',
|
|
201
|
+
onDone: {
|
|
202
|
+
target: 'updatingOption',
|
|
203
|
+
actions: ['setStatus'],
|
|
204
|
+
},
|
|
205
|
+
onError: {
|
|
206
|
+
target: 'pending',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
updatingOption: {
|
|
211
|
+
invoke: {
|
|
212
|
+
src: 'fetchOption',
|
|
213
|
+
onDone: {
|
|
214
|
+
target: 'pending',
|
|
215
|
+
actions: 'mergeOption',
|
|
216
|
+
},
|
|
217
|
+
onError: {
|
|
218
|
+
target: 'pending',
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
pending: {
|
|
223
|
+
after: {
|
|
224
|
+
20000: {
|
|
225
|
+
target: 'fetchingGameSHA',
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
176
231
|
},
|
|
177
232
|
},
|
|
178
233
|
{
|
|
@@ -200,19 +255,24 @@ export default function (request) {
|
|
|
200
255
|
}),
|
|
201
256
|
appendContent: assign((context, event) => {
|
|
202
257
|
const { room, favoriteList } = context
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
258
|
+
if (room.categoryId === GAME_SEARCH) {
|
|
259
|
+
return
|
|
260
|
+
} else {
|
|
261
|
+
const { data, ...rest } = event.data
|
|
262
|
+
return {
|
|
263
|
+
favoriteList: room.categoryId === MY_FAVORITE ? data : favoriteList,
|
|
264
|
+
content: {
|
|
265
|
+
...context.content,
|
|
266
|
+
...rest,
|
|
267
|
+
data: context.content.data.concat(data),
|
|
268
|
+
},
|
|
269
|
+
}
|
|
211
270
|
}
|
|
212
271
|
}),
|
|
213
272
|
swapContent: assign((context, event) => {
|
|
214
273
|
const { room, favoriteList } = context
|
|
215
|
-
|
|
274
|
+
const item = event.data
|
|
275
|
+
if (item.data?.length) {
|
|
216
276
|
return {
|
|
217
277
|
favoriteList: room.categoryId === MY_FAVORITE ? event.data.data : favoriteList,
|
|
218
278
|
content: event.data,
|
|
@@ -250,6 +310,7 @@ export default function (request) {
|
|
|
250
310
|
favoriteList: context.favoriteList.filter((item) => item.gameCode !== event.data.gameCode),
|
|
251
311
|
}
|
|
252
312
|
}),
|
|
313
|
+
...oldActions
|
|
253
314
|
},
|
|
254
315
|
guards: {
|
|
255
316
|
isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
|
|
@@ -257,6 +318,7 @@ export default function (request) {
|
|
|
257
318
|
hasRoom: (context, event) => context.room?.categoryId,
|
|
258
319
|
isFavorite: (context, event) => context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
259
320
|
isNotFavorite: (context, event) => !context.favoriteList.some((item) => item.gameCode === event.data.gameCode),
|
|
321
|
+
...oldGuards
|
|
260
322
|
},
|
|
261
323
|
services: {
|
|
262
324
|
getFavorite: async (context, event) => {
|
|
@@ -264,7 +326,9 @@ export default function (request) {
|
|
|
264
326
|
},
|
|
265
327
|
getPageContent: async (context, event) => {
|
|
266
328
|
const { room, index } = context
|
|
267
|
-
if (room.categoryId ===
|
|
329
|
+
if (room.categoryId === GAME_SEARCH) {
|
|
330
|
+
return
|
|
331
|
+
} else if (room.categoryId === MY_FAVORITE) {
|
|
268
332
|
return await request.send(api.getListMyFavorite())
|
|
269
333
|
} else {
|
|
270
334
|
return await request.send(api.getListCategory({ categoryId: room.categoryId, index }))
|
|
@@ -272,7 +336,9 @@ export default function (request) {
|
|
|
272
336
|
},
|
|
273
337
|
updatePageContent: async (context, event) => {
|
|
274
338
|
const { room, content, index } = context
|
|
275
|
-
if (room.categoryId ===
|
|
339
|
+
if (room.categoryId === GAME_SEARCH) {
|
|
340
|
+
return
|
|
341
|
+
} else if (room.categoryId === MY_FAVORITE) {
|
|
276
342
|
// return await request.send(api.getListMyFavorite({ timestamp: content.timestamp }))
|
|
277
343
|
} else {
|
|
278
344
|
return await request.send(
|
|
@@ -321,7 +387,55 @@ export default function (request) {
|
|
|
321
387
|
throw event.data
|
|
322
388
|
}
|
|
323
389
|
},
|
|
390
|
+
...oldServices(request)
|
|
324
391
|
},
|
|
325
392
|
}
|
|
326
393
|
)
|
|
327
394
|
}
|
|
395
|
+
|
|
396
|
+
const oldContext = {
|
|
397
|
+
sha: {
|
|
398
|
+
status: null,
|
|
399
|
+
},
|
|
400
|
+
isStatusChanged: false,
|
|
401
|
+
statusMap: {},
|
|
402
|
+
optionMap: {},
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const oldActions = {
|
|
406
|
+
setGameSHA: assign((context, event) => {
|
|
407
|
+
const { sha } = context
|
|
408
|
+
const newSha = event.data
|
|
409
|
+
return {
|
|
410
|
+
sha: newSha,
|
|
411
|
+
isStatusChanged: !sha.status || sha.status !== newSha.status,
|
|
412
|
+
}
|
|
413
|
+
}),
|
|
414
|
+
setStatus: assign((context, event) => {
|
|
415
|
+
return {
|
|
416
|
+
statusMap: event.data,
|
|
417
|
+
}
|
|
418
|
+
}),
|
|
419
|
+
mergeOption: assign((context, event) => {
|
|
420
|
+
const { optionMap } = context
|
|
421
|
+
return {
|
|
422
|
+
optionMap: { ...optionMap, ...event.data },
|
|
423
|
+
}
|
|
424
|
+
}),
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const oldGuards = {
|
|
428
|
+
isStatusChanged: (context, event) => context.isStatusChanged,
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const oldServices = (request) => ({
|
|
432
|
+
fetchOption: async (context, event) => {
|
|
433
|
+
return await request.send(api.getOptionMap())
|
|
434
|
+
},
|
|
435
|
+
fetchGameSHA: async (context, event) => {
|
|
436
|
+
return await request.send(api.getGameSHA())
|
|
437
|
+
},
|
|
438
|
+
fetchStatus: async (context, event) => {
|
|
439
|
+
return await request.send(api.getGameStatus())
|
|
440
|
+
},
|
|
441
|
+
})
|
package/src/machine/side_v2.js
CHANGED
|
@@ -73,8 +73,11 @@ export default function (request) {
|
|
|
73
73
|
return { menu }
|
|
74
74
|
}),
|
|
75
75
|
setDefaultMenuItemStack: assign((context, event) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
76
|
+
const menu = event.data
|
|
77
|
+
if (menu.data.length > 0) {
|
|
78
|
+
const menuItemStack = getDefaultItem(menu.data[0])
|
|
79
|
+
return { menuItemStack }
|
|
80
|
+
}
|
|
78
81
|
}),
|
|
79
82
|
setMenuItemStack: assign((context, event) => {
|
|
80
83
|
const { menuItemStack } = context
|
package/src/util/constant.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const MY_FAVORITE = 'MyFavorite'
|
|
1
|
+
export const MY_FAVORITE = 'MyFavorite'
|
|
2
|
+
export const GAME_SEARCH = 'GameSearch'
|